Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a list of all possible paths with react-router

I wonder if there's some way with React Router to get a list of all possible paths with the routes configuration?

For example, from this:

var routes = (
    <Route name="/">
        <DefaultRoute .../>
        <Route name="about" .../>
        <Route name="blog" .../>
    </Route>
);

I'd like:

["/", "/about", "/blog"]

like image 655
bjfletcher Avatar asked Sep 16 '25 21:09

bjfletcher


1 Answers

This seems to work for me, with v0.13:

var router = Router.create(routes);

var routePaths = [];
for (var i in router.namedRoutes) {
    routePaths.push(router.namedRoutes[i].path);
}

//routePaths = ['/', '/about', '/blog']
like image 157
Chris B Avatar answered Sep 18 '25 09:09

Chris B