mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 03:08:17 +02:00
fix(v2): docusaurus route config generation for empty path (#1683)
* fix(v2): route config does not acceptempty string * test snapshot * add test * changelog
This commit is contained in:
parent
2a1eb365fd
commit
71283dc7df
4 changed files with 55 additions and 4 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Fix docusaurus route config generation for certain edge case
|
||||||
|
|
||||||
## 2.0.0-alpha.22
|
## 2.0.0-alpha.22
|
||||||
|
|
||||||
- Add missing dependencies on `@docusaurus/preset-classic`
|
- Add missing dependencies on `@docusaurus/preset-classic`
|
||||||
|
|
|
@ -147,3 +147,42 @@ export default [
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`loadRoutes route config with empty (but valid) path string 1`] = `
|
||||||
|
Object {
|
||||||
|
"registry": Object {
|
||||||
|
"component---hello-world-jse-0-f-b6c": Object {
|
||||||
|
"importStatement": "() => import(/* webpackChunkName: 'component---hello-world-jse-0-f-b6c' */ \\"hello/world.js\\")",
|
||||||
|
"modulePath": "hello/world.js",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"routesChunkNames": Object {
|
||||||
|
"": Object {
|
||||||
|
"component": "component---hello-world-jse-0-f-b6c",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"routesConfig": "
|
||||||
|
import React from 'react';
|
||||||
|
import ComponentCreator from '@docusaurus/ComponentCreator';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: ComponentCreator(''),
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: '*',
|
||||||
|
component: ComponentCreator('*')
|
||||||
|
}
|
||||||
|
];
|
||||||
|
",
|
||||||
|
"routesPaths": Array [
|
||||||
|
"404.html",
|
||||||
|
"",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
|
@ -73,7 +73,7 @@ describe('loadRoutes', () => {
|
||||||
} as RouteConfig;
|
} as RouteConfig;
|
||||||
|
|
||||||
expect(loadRoutes([routeConfigWithoutPath])).rejects.toMatchInlineSnapshot(`
|
expect(loadRoutes([routeConfigWithoutPath])).rejects.toMatchInlineSnapshot(`
|
||||||
[Error: Invalid routeConfig (Path and component is required)
|
[Error: Invalid routeConfig (Path must be a string and component is required)
|
||||||
{"component":"hello/world.js"}]
|
{"component":"hello/world.js"}]
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -83,8 +83,18 @@ describe('loadRoutes', () => {
|
||||||
|
|
||||||
expect(loadRoutes([routeConfigWithoutComponent])).rejects
|
expect(loadRoutes([routeConfigWithoutComponent])).rejects
|
||||||
.toMatchInlineSnapshot(`
|
.toMatchInlineSnapshot(`
|
||||||
[Error: Invalid routeConfig (Path and component is required)
|
[Error: Invalid routeConfig (Path must be a string and component is required)
|
||||||
{"path":"/hello/world"}]
|
{"path":"/hello/world"}]
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('route config with empty (but valid) path string', async () => {
|
||||||
|
const routeConfig = {
|
||||||
|
path: '',
|
||||||
|
component: 'hello/world.js',
|
||||||
|
} as RouteConfig;
|
||||||
|
|
||||||
|
const result = await loadRoutes([routeConfig]);
|
||||||
|
expect(result).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,9 +41,9 @@ export async function loadRoutes(pluginsRouteConfigs: RouteConfig[]) {
|
||||||
exact,
|
exact,
|
||||||
} = routeConfig;
|
} = routeConfig;
|
||||||
|
|
||||||
if (!routePath || !component) {
|
if (!_.isString(routePath) || !component) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid routeConfig (Path and component is required) \n${JSON.stringify(
|
`Invalid routeConfig (Path must be a string and component is required) \n${JSON.stringify(
|
||||||
routeConfig,
|
routeConfig,
|
||||||
)}`,
|
)}`,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue