From cd177a6fa98124e7a1fa6eb7af1b655d94d863b7 Mon Sep 17 00:00:00 2001 From: Vordgi Date: Sun, 18 Feb 2024 15:29:12 +0400 Subject: [PATCH] get-15 fix get-params for optional catch-all routes --- package/src/get-params.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package/src/get-params.ts b/package/src/get-params.ts index a39788b..5a03da9 100644 --- a/package/src/get-params.ts +++ b/package/src/get-params.ts @@ -19,8 +19,9 @@ export const getParams = () => { const isRootPage = cleanUrlPathname === '' && cleanPagePath === ''; const isNotFoundPage = pagePath.match(/\/_not-found\/?$/); - const isValidCatchALl = cleanPagePath.match(/\[\.\.\.[^\]]+\]/) && pathnameParts.length >= pagePathInterceptedParts.length; - const isCorrectMatched = isRootPage || isNotFoundPage || pagePathInterceptedParts.length === pathnameParts.length || isValidCatchALl; + const isValidCatchALl = cleanPagePath.match(/\/\[\.\.\.[^\]]+\]/) && pathnameParts.length >= pagePathInterceptedParts.length; + const isValidOptionalCatchALl = cleanPagePath.match(/\/\[\[\.\.\.[^\]]+\]\]/) && pathnameParts.length >= pagePathInterceptedParts.length - 1; + const isCorrectMatched = isRootPage || isNotFoundPage || pagePathInterceptedParts.length === pathnameParts.length || isValidCatchALl || isValidOptionalCatchALl; if (!isCorrectMatched) { const createIssueUrl = new URL('https://github.com/vordgi/next-impl-getters/issues/new')