【问题标题】:React router: reload new page反应路由器:重新加载新页面
【发布时间】:2017-05-17 02:55:38
【问题描述】:

例如我有这样的路线:

  • /login:用于登录屏幕
  • /home:用于主屏幕

在主屏幕上,我注销,我希望它在加载新页面时再次进入 /login 屏幕(因此所有状态都是新的)。如何使用 React 路由器在 React 中做到这一点。

【问题讨论】:

  • window.location = '/login' ?你能提供更多的上下文吗? React 不提供路由。您目前如何进行路由?
  • 我已经编辑了我的问题。我正在使用 React Router 库。感谢您的评论。

标签: reactjs react-router


【解决方案1】:

您可以像这样“重定向”:

import { browserHistory } from "react-router";

browserHistory.push('/someroute');

如果你想重置你的状态 - 在componentWillReceiveProps进行操作

  componentWillReceiveProps(nextProps) {
  var currentLocation = nextProps.location.pathname;
  if(currentLocation=='someroute')
    //your logic
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-13
    • 1970-01-01
    • 2018-05-24
    • 2020-07-11
    相关资源
    最近更新 更多