使用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