Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react router - get current route

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?

like image 902
Bomber Avatar asked Nov 01 '22 01:11

Bomber


1 Answers

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.

like image 163
Alex Moldovan Avatar answered Nov 09 '22 16:11

Alex Moldovan