1
使用react 15.1.0
和react-router 2.5.2
,我想重写以下JSX语法:如何使用反应路由器将重定向重写为普通路由?
<Router routes={routes} history={hashHistory}>
<Redirect from="/" to="/users" />
<Route path="/" component={Navigation}>
<Route path="/users" component={UsersPage}/>
<Route path="/endpoints" component={EndpointsPage}/>
</Route>
</Router>
成普通路线,像这样:
const routes = {
path: '/',
component: Navigation,
childRoutes: [
{path: '/users', component: UsersPage},
{path: '/endpoints', component: EndpointsPage}
],
onEnter: (nextState, replace) => replace('/users')
};
React.render(<Router routes={routes} history={hashHistory}/>, element);
但是后者的结果总是:
Uncaught RangeError: Maximum call stack size exceeded
onEnter: (nextState, replace) => replace('/users')
显然不足以取代<Redirect from="/" to="/users" />
。我怎样才能成功重写重定向?有没有更好的方法使导航到/
总是最终在/users
?