File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
packages/react-router-dom Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -1255,13 +1255,11 @@ function useScrollRestoration({
1255
1255
// Enable scroll restoration in the router
1256
1256
// eslint-disable-next-line react-hooks/rules-of-hooks
1257
1257
React . useLayoutEffect ( ( ) => {
1258
- let disableScrollRestoration = router ?. enableScrollRestoration (
1259
- savedScrollPositions ,
1260
- ( ) => window . scrollY ,
1261
- getKey
1258
+ let getKeyWithoutBasename : GetScrollRestorationKeyFunction | undefined =
1259
+ getKey && basename !== "/"
1262
1260
? ( location , matches ) =>
1263
1261
getKey (
1264
- // Strip the basename to match useLocation
1262
+ // Strip the basename to match useLocation()
1265
1263
{
1266
1264
...location ,
1267
1265
pathname :
@@ -1270,7 +1268,11 @@ function useScrollRestoration({
1270
1268
} ,
1271
1269
matches
1272
1270
)
1273
- : undefined
1271
+ : getKey ;
1272
+ let disableScrollRestoration = router ?. enableScrollRestoration (
1273
+ savedScrollPositions ,
1274
+ ( ) => window . scrollY ,
1275
+ getKeyWithoutBasename
1274
1276
) ;
1275
1277
return ( ) => disableScrollRestoration && disableScrollRestoration ( ) ;
1276
1278
} , [ router , basename , getKey ] ) ;
You can’t perform that action at this time.
0 commit comments