2017-02-17 39 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