React路由器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'

有人知道为什么会发生这种情况?

为什么不使用<IndexRedirect>组件?

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

问题是:

(nextState, replace) => { replace({ pathName: 'getStarted' }); }

因为"pathName"不是"pathname"(小写) - React -Rououter历史模块的内部工作原理默认将重定向到"/",这是当前路径,创建循环。

问题在此处打开:https://github.com/reacttraining/reaect-router/issues/4545

最新更新