javascript - react router - get current route - Stack Overflow

I have the following routes, is it possible to get the current route name and apply its own handler?

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 badges
Add a ment  | 

1 Answer 1

Reset to default 2

The 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745165239a4614591.html

相关推荐

  • javascript - react router - get current route - Stack Overflow

    I have the following routes, is it possible to get the current route name and apply its own handler?

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信