mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-19 01:28:38 +02:00
Merge 25d45e884a
into 0306d18240
This commit is contained in:
commit
7ab303224b
4 changed files with 38 additions and 0 deletions
|
@ -113,6 +113,10 @@ declare module '@theme/NotFound' {
|
|||
export default function NotFound(): ReactNode;
|
||||
}
|
||||
|
||||
declare module '@theme/NotFound/Content' {
|
||||
export default function NotFoundContent(): JSX.Element;
|
||||
}
|
||||
|
||||
declare module '@theme/Root' {
|
||||
import type {ReactNode} from 'react';
|
||||
|
||||
|
|
|
@ -234,6 +234,14 @@ export async function buildAllRoutes(
|
|||
}),
|
||||
),
|
||||
);
|
||||
// Add a catch-all route for 404 support if routeBasePath is "/".
|
||||
// (see https://github.com/facebook/docusaurus/issues/9688)
|
||||
if (param.options.routeBasePath === '/') {
|
||||
subRoutes.push({
|
||||
path: '/*',
|
||||
component: '@docusaurus/ComponentCreator',
|
||||
});
|
||||
}
|
||||
|
||||
// all docs routes are wrapped under a single parent route, this ensures
|
||||
// the theme layout never unmounts/remounts when navigating between versions
|
||||
|
|
|
@ -43,6 +43,24 @@ export default function ComponentCreator(
|
|||
},
|
||||
});
|
||||
}
|
||||
if (path.endsWith('/*')) {
|
||||
return Loadable({
|
||||
loading: Loading,
|
||||
loader: () => import('@theme/NotFound/Content'),
|
||||
modules: ['@theme/NotFound/Content'],
|
||||
webpack: () => [require.resolveWeak('@theme/NotFound/Content')],
|
||||
render(loaded, props) {
|
||||
const NotFoundContent = loaded.default;
|
||||
return (
|
||||
<RouteContextProvider
|
||||
// Do we want a better name than native-default?
|
||||
value={{plugin: {name: 'native', id: 'default'}}}>
|
||||
<NotFoundContent {...(props as JSX.IntrinsicAttributes)} />
|
||||
</RouteContextProvider>
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const chunkNames = routesChunkNames[`${path}-${hash}`]!;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
|
@ -43,6 +43,14 @@ export function sortRoutes<Route extends RouteConfig>(
|
|||
return -1;
|
||||
}
|
||||
|
||||
// Wildcard also should get placed last
|
||||
if (a.path.endsWith('/*')) {
|
||||
return 1;
|
||||
}
|
||||
if (b.path.endsWith('/*')) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (a.routes && !b.routes) {
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue