How to use react-router 4.0 to refresh current route? not reload the whole page

后端 未结 7 2114
暖寄归人
暖寄归人 2021-01-01 19:35

\'react-router-dom\' has refresh function here, but I don\'t know how to call this method, also their well formatted document doesn\'t bother to explain this.

windo

7条回答
  •  伪装坚强ぢ
    2021-01-01 20:17

    You could use this little trick. Push a new path in the history like history.push('/temp') and immediately call the history.goBack()

    Here the example:

    Create an history and pass it to the router:

    import { createBrowserHistory } from "history";
    
    export const appHistory = createBrowserHistory();
    
    
      
      
    
    

    then somewhere in your app, change the history:

    appHistory.push('/temp');
    appHistory.goBack();
    

    In this way the route will "remain" the same, and will be refreshed.

提交回复
热议问题