diff --git a/packages/docusaurus/src/client/preload.ts b/packages/docusaurus/src/client/preload.ts index fec374ad4b6b9..8d96f77a11116 100644 --- a/packages/docusaurus/src/client/preload.ts +++ b/packages/docusaurus/src/client/preload.ts @@ -7,6 +7,7 @@ import routes from '@generated/routes'; import {matchRoutes} from 'react-router-config'; +import { uniq } from 'lodash'; /** * Helper function to make sure all async components for that particular route @@ -17,7 +18,9 @@ import {matchRoutes} from 'react-router-config'; * @returns Promise object represents whether pathname has been preloaded */ export default function preload(pathname: string): Promise { - const matches = matchRoutes(routes, pathname); + const matches = [pathname, decodeURI(pathname)] + .map(p => matchRoutes(routes, p)) + .flat(); - return Promise.all(matches.map((match) => match.route.component.preload?.())); + return Promise.all(uniq(matches.map((match) => match.route.component)).map(c => c.preload?.())); }