使用App
处理程序两次按照您期望的方式工作 - 它称为App twice. However, the parent should only be used as the parent
路由处理程序, and the children use their own
处理程序。
获取初始页面正常加载,使用DefaultRoute
的基本路径:
路线
var routes = (
<Route name="app" path="/" handler={App}>
<DefaultRoute handler={Home}/>
<Route name="paginated" path="page/:page" handler={Page} />
</Route>
);
应用
var App = React.createClass({
render : function() {
return (
<div>
<RouteHandler/>
</div>
);
}
});
家
var Home = React.createClass({
render : function() {
return (
<div>
...Something...
</div>
);
}
});
页
var Page = React.createClass({
render : function() {
return (
<div>
...Something Completely Different...
</div>
);
}
});
的阵营路由器默认的处理程序文件有较大幅度的例子:
<Route path="/" handler={App}>
<!--
When the url is `/`, this route will be active. In other
words, `Home` will be the `<RouteHandler/>` in `App`.
-->
<DefaultRoute handler={Home}/>
<Route name="about" handler={About}/>
<Route name="users" handler={Users}>
<Route name="user" handler={User} path="/user/:id"/>
<!-- when the url is `/users`, this will be active -->
<DefaultRoute name="users-index" handler={UsersIndex}/>
</Route>
</Route>
注意这里<Route name="user" handler={User} path="/user/:id"/>
也有一个默认路由,所以当没有:id
匹配它有某处去。
希望这会有所帮助!
感谢您的回复!这是我的第一个想法,但如果我需要在'paginated'中嵌套路线(实际上是这种情况),它不会真正起作用。 – ThisIsErico