2017-02-19 111 views
1

我使用的反應,路由器routes參數:陣營路由器 - 重定向使用indexRoute

const rootRoute = { 
    component: App, 
    childRoutes: createRoutes(store), 
    indexRoute: { onEnter: (nextState, replace) => replace('/new-url') } 
}; 

這裏是Router JSX部分:

<Router 
    history={hashHistory} 
    routes={rootRoute}> 
</Router> 

indexRoute是我試圖線添加重定向但它不起作用。

+0

@EQuimper除了indexRouter以外,一切都按預期工作,所以我猜測沒關係。 – Dekel

+0

您可以使用[''](https://github.com/ReactTraining/react-router/blob/master/docs/guides/IndexRoutes.md#index-redirects)組件。 –

+0

@MingSoon - 我需要這個作爲'rootRoute = {}'對象的一部分,你有這樣的例子嗎? – Dekel

回答

1

您需要將path: '/'添加到rootRoute

+0

任何解釋此解決方案的機會?爲什麼沒有'路徑'不能工作? – Dekel

+0

我覺得沒有'path'配置,路由器不知道什麼時候進入'indexRoute'。 –

+0

只是投了你的答案,我會盡可能接受它。 – Dekel