This commit is contained in:
Josh Cannon 2025-07-10 13:16:19 +02:00 committed by GitHub
commit 7ab303224b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 0 deletions

View file

@ -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';

View file

@ -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

View file

@ -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

View file

@ -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;
}