2017-02-17 43 views
0

我的路线是这样的:阵营路由器终极版 - 无限循环从IndexRoute重定向时

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'

人知道为什么发生?

回答

1

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

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

发行开幕。 –

0

的问题是这样的:

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

因为"pathName"没有"pathname"(小写) - 反应 - 路由器的历史模块的内部工作被拖欠重定向到"/"这是当前路径,创建循环。因为在我的实际应用中`onEnter`逻辑并不像在示例中提供的一个简单https://github.com/ReactTraining/react-router/issues/4545