Skip to content

Commit

Permalink
Refactor: initialize currentPath
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Mar 7, 2022
1 parent db853d6 commit c40d022
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/hydrogen/src/foundation/Router/Router.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type RouterContextValue = {

const RouterContext = createContext<RouterContextValue | {}>({});

let currentPath = '';
let currentPath = window.location.pathname;

export const Router: FC<{history?: BrowserHistory}> = ({
history: pHistory,
Expand All @@ -34,10 +34,9 @@ export const Router: FC<{history?: BrowserHistory}> = ({
if (firstLoad) setFirstLoad(false);
// A navigation event has just happened
else if (!pending && currentPath !== serverState.pathname) {
currentPath = serverState.pathname;
window.scrollTo(0, 0);
}

currentPath = serverState.pathname;
}, [pending]);

useEffect(() => {
Expand Down

0 comments on commit c40d022

Please sign in to comment.