From 41648a84d2552c0a6ed63c0dab2c27aebbfd805a Mon Sep 17 00:00:00 2001 From: Dionysos Dajka Date: Fri, 5 Nov 2021 12:58:57 +0100 Subject: [PATCH] fix(useBackLink): Fix inverted subpath logic, #164 --- src/useBackLink/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/useBackLink/index.ts b/src/useBackLink/index.ts index 7890c5de..5f9159ea 100644 --- a/src/useBackLink/index.ts +++ b/src/useBackLink/index.ts @@ -19,9 +19,11 @@ function useBackLink(options: BackLinkOptions = {}): Location | null { } function getShouldSkipLocation(location) { - const ignoreSubpath = basePath?.startsWith( - stripSlashFromEnd(getLocationPathname(location)) - ); + const formattedLocation = basePath + ? stripSlashFromEnd(getLocationPathname(location)) + : null; + + const ignoreSubpath = formattedLocation?.startsWith(basePath); const skipLocation = shouldSkipLocation?.(location); @@ -42,6 +44,8 @@ function useBackLink(options: BackLinkOptions = {}): Location | null { const backLink = getBackLink(); + console.log(basePath, historyStack); + return backLink || fallback; }