mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
feat(v2): enable exact for addRoute API (#1374)
This commit is contained in:
parent
1d7538ff4a
commit
2a13c7773f
4 changed files with 13 additions and 11 deletions
|
@ -128,6 +128,7 @@ class DocusaurusPluginContentBlog {
|
|||
addRoute({
|
||||
path: permalink,
|
||||
component: blogPageComponent,
|
||||
exact: true,
|
||||
metadata: metadataItem,
|
||||
modules: {
|
||||
entries: metadataItem.posts.map(post => ({
|
||||
|
@ -147,6 +148,7 @@ class DocusaurusPluginContentBlog {
|
|||
addRoute({
|
||||
path: permalink,
|
||||
component: blogPostComponent,
|
||||
exact: true,
|
||||
metadata: metadataItem,
|
||||
modules: {
|
||||
content: metadataItem.source,
|
||||
|
|
|
@ -214,6 +214,7 @@ class DocusaurusPluginContentDocs {
|
|||
routes: Object.values(content.docs).map(metadataItem => ({
|
||||
path: metadataItem.permalink,
|
||||
component: docItemComponent,
|
||||
exact: true,
|
||||
metadata: metadataItem,
|
||||
modules: {
|
||||
content: metadataItem.source,
|
||||
|
|
|
@ -103,6 +103,7 @@ class DocusaurusPluginContentPages {
|
|||
addRoute({
|
||||
path: permalink,
|
||||
component,
|
||||
exact: true,
|
||||
metadata: metadataItem,
|
||||
modules: {
|
||||
content: source,
|
||||
|
|
|
@ -58,6 +58,7 @@ async function loadRoutes(pluginsRouteConfigs) {
|
|||
metadata,
|
||||
modules = {},
|
||||
routes,
|
||||
exact,
|
||||
} = routeConfig;
|
||||
|
||||
addRoutesPath(routePath);
|
||||
|
@ -90,15 +91,6 @@ async function loadRoutes(pluginsRouteConfigs) {
|
|||
const componentChunk = genImportChunk(componentPath, 'component');
|
||||
addRoutesChunkNames(routePath, 'component', componentChunk);
|
||||
|
||||
if (routes) {
|
||||
return `
|
||||
{
|
||||
path: '${routePath}',
|
||||
component: ComponentCreator('${routePath}'),
|
||||
routes: [${routes.map(generateRouteCode).join(',')}],
|
||||
}`;
|
||||
}
|
||||
|
||||
function genRouteChunkNames(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(genRouteChunkNames);
|
||||
|
@ -132,11 +124,17 @@ async function loadRoutes(pluginsRouteConfigs) {
|
|||
addRoutesChunkNames(routePath, 'metadata', metadataChunk);
|
||||
}
|
||||
|
||||
const routesStr = routes
|
||||
? `routes: [${routes.map(generateRouteCode).join(',')}],`
|
||||
: '';
|
||||
const exactStr = exact ? `exact: true,` : '';
|
||||
|
||||
return `
|
||||
{
|
||||
path: '${routePath}',
|
||||
exact: true,
|
||||
component: ComponentCreator('${routePath}')
|
||||
component: ComponentCreator('${routePath}'),
|
||||
${exactStr}
|
||||
${routesStr}
|
||||
}`;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue