2017-02-19 114 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