ScrollRestoration
接受参数
getKey
storageKey
,推荐将其放置在
root route
中(例如
Layout
),且只需要在
root
中渲染一个即可运行。
function RootRouteComponent() {
return (
{}
<ScrollRestoration
getKey={(location, matches) => {
const paths = ['/home', '/notifications'];
return paths.includes(location.pathname)
?
location.pathname
:
location.key;
</div>