diff --git a/packages/docusaurus/src/client/normalizeLocation.ts b/packages/docusaurus/src/client/normalizeLocation.ts index 37c55b4000f0..74192a451c08 100644 --- a/packages/docusaurus/src/client/normalizeLocation.ts +++ b/packages/docusaurus/src/client/normalizeLocation.ts @@ -10,13 +10,13 @@ import routes from '@generated/routes'; import type {Location} from 'history'; // Memoize previously normalized pathnames. -const pathnames: {[rawPathname: string]: string} = {}; +const pathnames = new Map(); export default function normalizeLocation(location: T): T { - if (pathnames[location.pathname]) { + if (pathnames.has(location.pathname)) { return { ...location, - pathname: pathnames[location.pathname], + pathname: pathnames.get(location.pathname), }; } @@ -24,14 +24,14 @@ export default function normalizeLocation(location: T): T { // away, or it will render to a 404 page. const matchedRoutes = matchRoutes(routes, location.pathname); if (matchedRoutes.some(({route}) => route.exact === true)) { - pathnames[location.pathname] = location.pathname; + pathnames.set(location.pathname, location.pathname); return location; } const pathname = location.pathname.trim().replace(/(?:\/index)?\.html$/, '') || '/'; - pathnames[location.pathname] = pathname; + pathnames.set(location.pathname, pathname); return { ...location,