Skip to content

Commit

Permalink
fix: preload with encoded page links
Browse files Browse the repository at this point in the history
  • Loading branch information
adventure-yunfei committed Aug 18, 2022
1 parent eac3239 commit 61ebe60
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/docusaurus/src/client/preload.ts
Expand Up @@ -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
Expand All @@ -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<void[]> {
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?.()));
}

0 comments on commit 61ebe60

Please sign in to comment.