From 45bff2423eeb85a24f1265c88c8c7b7448bed4d6 Mon Sep 17 00:00:00 2001 From: Mister-Hope Date: Mon, 20 May 2024 13:09:41 +0800 Subject: [PATCH] fix(core): fix pathInferred compare logic --- .../core/src/app/prepare/prepareRoutes.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/core/src/app/prepare/prepareRoutes.ts b/packages/core/src/app/prepare/prepareRoutes.ts index fc7780be46..b3556e8041 100644 --- a/packages/core/src/app/prepare/prepareRoutes.ts +++ b/packages/core/src/app/prepare/prepareRoutes.ts @@ -27,20 +27,15 @@ const resolvePageRedirects = ({ path, pathInferred }: Page): string[] => { // paths that should redirect to this page, use set to dedupe const redirectsSet = new Set() - // add redirect to the set when the redirect could not be normalized & encoded to the page path - const addRedirect = (redirect: string): void => { - const normalizedPath = normalizeRoutePath(redirect) - if (normalizedPath === path) return - - const encodedPath = encodeURI(normalizedPath) - if (encodedPath === path) return - - redirectsSet.add(redirect) - } - // redirect from inferred path, notice that the inferred path is not uri-encoded if (pathInferred !== null) { - addRedirect(encodeURI(pathInferred)) + const normalizedPathInferred = normalizeRoutePath(pathInferred) + const encodedPathInferred = encodeURI(normalizedPathInferred) + + // add redirect to the set when the redirect could not be normalized & encoded to the page path + if (normalizedPathInferred !== path && encodedPathInferred !== path) { + redirectsSet.add(encodedPathInferred) + } } return Array.from(redirectsSet)