How do people handle scroll restoration with react-router v4?

前端 未结 5 423
一整个雨季
一整个雨季 2020-12-28 17:30

I\'m experiencing some problems with scroll positions on the back button (history popstate) when using react-router. React router v4 doesn\'t handle scroll management out of

5条回答
  •  -上瘾入骨i
    2020-12-28 18:06

    How do you handle your scroll restoration?

    Turns out browsers have implementations of the history.scrollRestoration.

    Maybe you can use that? Check these links out.

    https://developer.mozilla.org/en/docs/Web/API/History#Specifications https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration

    In addition, I found an npm module that might be able to handle scroll restoration in react with ease, but this library only works with react router v3 and below

    https://www.npmjs.com/package/react-router-restore-scroll https://github.com/ryanflorence/react-router-restore-scroll

    I hope this can help.

提交回复
热议问题