How do I reload a page with react-router?

后端 未结 13 1770
臣服心动
臣服心动 2020-12-09 08:23

I can see in this file (https://github.com/ReactTraining/react-router/blob/v0.13.3/modules/createRouter.js) that there is a refresh function but I have no idea how to call i

13条回答
  •  自闭症患者
    2020-12-09 09:12

    This solution won't cause the undesired full page reload but requires you to make this modification to each page that needs refreshing:

    export const Page = () => {
       const location = useLocation();
       return 
    }
    

    So the idea is: create a wrapper around your page and make React re-create the actual page every time the location key changes.

    Now it's enough to call history.push(/this-page-route) again and the page refreshes.

提交回复
热议问题