From b1a13af3d1632b00b3d40e291e8221b4f08dbcb6 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Tue, 17 Dec 2024 15:34:10 -0300 Subject: [PATCH] fix(usePathname): prevent duplication of subpath in pathname --- app/scripts/utils/use-pathname.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/scripts/utils/use-pathname.ts b/app/scripts/utils/use-pathname.ts index 702649e04..dba509cc5 100644 --- a/app/scripts/utils/use-pathname.ts +++ b/app/scripts/utils/use-pathname.ts @@ -13,14 +13,18 @@ import { useEffect, useState } from 'react'; */ export const usePathname = () => { const [pathname, setPathname] = useState( - typeof window !== 'undefined' ? window.location.pathname : '' + typeof window !== 'undefined' + ? window.location.pathname.replace(process.env.PUBLIC_URL ?? '', '') + : '' ); useEffect(() => { if (typeof window === 'undefined') return; const updatePathname = () => { - setPathname(window.location.pathname); + setPathname( + window.location.pathname.replace(process.env.PUBLIC_URL ?? '', '') + ); }; // Listen to popstate events (back/forward navigation)