How do I reload a page with react-router?

后端 未结 13 1815
臣服心动
臣服心动 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 08:57

    I guess that you're using react-router. I'll copy my answer from another post. So you have few possibilities to do that, currently my favorite way to do that is using anonymous function in component prop:

    
      } />
      } />
      }/>
    
    

    Or if you want to refresh with current url params, you'll need extra route (reload), and play a little with router stack:

    reload = ()=>{
     const current = props.location.pathname;
     this.props.history.replace(`/reload`);
        setTimeout(() => {
          this.props.history.replace(current);
        });
    }
    
    
      
      
      
      
    
    
    
    Reload

提交回复
热议问题