【问题标题】:redirect in react-router undefined?在反应路由器中重定向未定义?
【发布时间】:2017-05-10 15:13:16
【问题描述】:

这就是我的 react-router 代码的样子

render((
<Router history={browserHistory}>
    <Route path={CORP} component={App}>
      <IndexRoute component={Home} />
      <Route path={"outreach"} component={OutReach}/>
      <Route path={"careers/m"} component={Career}/>
      <Route path={"members"} component={Members}/>
      <Redirect from="*" to={"/home"} />
    </Route>
  </Router>
), document.getElementById('app'))

但是当我转到我的页面时,我在控制台中收到此错误

未捕获的引用错误:未定义重定向

我如何告诉 react-router 仅当用户的目的地与上述任何路由路径都不匹配时才将用户重定向到/home

【问题讨论】:

    标签: react-router


    【解决方案1】:

    你只需要添加

    import { Redirect } from 'react-router';
    

    在文件的顶部

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-13
      • 2020-10-22
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多