Reactjs 如何使用react路由器从嵌套路由的根重定向?

Reactjs 如何使用react路由器从嵌套路由的根重定向?,reactjs,react-router,Reactjs,React Router,没有在网上找到任何答案,基本上我希望应用程序自动从我的路由根(/)重定向到“posts”。所以www.app.com/user/1变成了www.app.com/user/1/posts 我试着使用重定向,但实际上它什么也没做 <Router history={browserHistory}> <Route path="/" component={App}> <IndexRoute component={HomePage}></In

没有在网上找到任何答案,基本上我希望应用程序自动从我的路由根(/)重定向到“posts”。所以
www.app.com/user/1
变成了
www.app.com/user/1/posts

我试着使用重定向,但实际上它什么也没做

<Router history={browserHistory}>
    <Route path="/" component={App}>
        <IndexRoute component={HomePage}></IndexRoute>
        <Route path="user/:id" component={UserPage}>
            <Route path="tracks" component={UserPosts}></Route>
            <Redirect from="/" to="posts"/>
        </Route>
  </Route>
</Router>


尝试将重定向组件放在上面,但仍然不起作用。有什么想法吗?

我们在项目中使用的解决方案基于
IndexRoute

<IndexRoute onEnter={redirectToMainPage} />
这将允许动态选择重定向

此外,您还可以使用
IndexRedirect

<IndexRedirect to="/firstPage" />


我认为,如果从中的
/
开始,则
采用绝对路径,一般来说,空路径的可靠性较低。

我们在项目中使用的解决方案基于
IndexRoute

<IndexRoute onEnter={redirectToMainPage} />
这将允许动态选择重定向

此外,您还可以使用
IndexRedirect

<IndexRedirect to="/firstPage" />

我认为,如果从的中的/开始,则采用绝对路径,一般来说,空路径的可靠性较低