admin管理员组文章数量:1415460
I have the following routes, is it possible to get the current route name and apply its own handler?
var routes = (
<Route name="app" path="/" handler={OurSchoolsApp}>
<DefaultRoute name="home" handler={HomePage} />
<Route name="add-school" handler={AddSchoolPage} />
<Route name="calendar" handler={CalendarPage} />
<Route name="calendar-detail" path="calendar-detail/:id" handler={CalendarDetailPage} />
<Route name="info-detail" path="info-detail/:id" handler={InfoDetailPage} />
<Route name="info" handler={InfoPage} />
<Route name="news" handler={NewsListPage} />
<Route name="news-detail" path="news-detail/:id" handler={NewsDetailPage} />
<Route name="contacts" handler={ContactPage} />
<Route name="contact-detail" handler={ContactDetailPage} />
<Route name="settings" handler={SettingsPage} />
</Route>
);
How do I get the current route name?
I want to do something like this?
Router.run(routes, function(Handler){
var mountNode = document.getElementById('app');
if(isRoute('home')){
React.render(<Handler title="Home Page" /> , mountNode);
}else{
React.render(<Handler title="default" /> , mountNode);
}
});
Can anyone help?
I have the following routes, is it possible to get the current route name and apply its own handler?
var routes = (
<Route name="app" path="/" handler={OurSchoolsApp}>
<DefaultRoute name="home" handler={HomePage} />
<Route name="add-school" handler={AddSchoolPage} />
<Route name="calendar" handler={CalendarPage} />
<Route name="calendar-detail" path="calendar-detail/:id" handler={CalendarDetailPage} />
<Route name="info-detail" path="info-detail/:id" handler={InfoDetailPage} />
<Route name="info" handler={InfoPage} />
<Route name="news" handler={NewsListPage} />
<Route name="news-detail" path="news-detail/:id" handler={NewsDetailPage} />
<Route name="contacts" handler={ContactPage} />
<Route name="contact-detail" handler={ContactDetailPage} />
<Route name="settings" handler={SettingsPage} />
</Route>
);
How do I get the current route name?
I want to do something like this?
Router.run(routes, function(Handler){
var mountNode = document.getElementById('app');
if(isRoute('home')){
React.render(<Handler title="Home Page" /> , mountNode);
}else{
React.render(<Handler title="default" /> , mountNode);
}
});
Can anyone help?
Share Improve this question asked Jun 17, 2015 at 11:01 BomberBomber 11k27 gold badges97 silver badges175 bronze badges1 Answer
Reset to default 2The second parameter of the callback function of Router.run is the state object. You can see here all the values that the state holds, you can use something from there.
本文标签: javascriptreact routerget current routeStack Overflow
版权声明:本文标题:javascript - react router - get current route - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745165238a2645640.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论