Skip to content

Commit 797fcb1

Browse files
committed
Code cleanup
1 parent 485e475 commit 797fcb1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/react-router-dom/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,13 +1255,11 @@ function useScrollRestoration({
12551255
// Enable scroll restoration in the router
12561256
// eslint-disable-next-line react-hooks/rules-of-hooks
12571257
React.useLayoutEffect(() => {
1258-
let disableScrollRestoration = router?.enableScrollRestoration(
1259-
savedScrollPositions,
1260-
() => window.scrollY,
1261-
getKey
1258+
let getKeyWithoutBasename: GetScrollRestorationKeyFunction | undefined =
1259+
getKey && basename !== "/"
12621260
? (location, matches) =>
12631261
getKey(
1264-
// Strip the basename to match useLocation
1262+
// Strip the basename to match useLocation()
12651263
{
12661264
...location,
12671265
pathname:
@@ -1270,7 +1268,11 @@ function useScrollRestoration({
12701268
},
12711269
matches
12721270
)
1273-
: undefined
1271+
: getKey;
1272+
let disableScrollRestoration = router?.enableScrollRestoration(
1273+
savedScrollPositions,
1274+
() => window.scrollY,
1275+
getKeyWithoutBasename
12741276
);
12751277
return () => disableScrollRestoration && disableScrollRestoration();
12761278
}, [router, basename, getKey]);

0 commit comments

Comments
 (0)