From 61ebe60178301e5fdae80e80c210dac5d2557998 Mon Sep 17 00:00:00 2001 From: adventure-yunfei Date: Thu, 18 Aug 2022 14:39:44 +0800 Subject: [PATCH] fix: preload with encoded page links --- packages/docusaurus/src/client/preload.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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?.())); }