React Router Redux - 从IndexRoute重定向时的无限循环

时间:2017-02-17 19:55:55

标签: reactjs react-router infinite-loop react-router-redux

我的路线如下:

render(
  <Provider store={store}>
    <Router history={history}>
      <Route path="/" component={App}>
        <IndexRoute component={SEOModuleComponent} onEnter={(nextState, replace) => { replace({ pathName: 'getStarted' }); }} onChange={() => {}} />
        <Route path="getStarted" component={GetStartedView} onChange={() => {}} />
      </Route>
    </Router>
  </Provider>,
  document.getElementById('app-container')
);

当我加载应用程序时 - 它会不断尝试重定向到'getStarted'

进入无限循环

任何人都知道为什么会这样吗?

2 个答案:

答案 0 :(得分:1)

为什么不使用WP Contacts组件?

<Router history={history}>
  <Route path="/" component={App}>
    <IndexRedirect to="/getStarted" />
    <Route path="getStarted" component={GetStartedView} onChange={() => {}} />
  </Route>
</Router>

答案 1 :(得分:0)

问题在于:

Othername

因为 (nextState, replace) => { replace({ pathName: 'getStarted' }); } 不是"pathName"(小写) - react-router的历史模块的内部工作方式是默认重定向到当前路径的"pathname",从而创建循环。

此处打开了问题:https://github.com/ReactTraining/react-router/issues/4545