Respond delivery routes, if configured using a react router

Is there a command on the console that I can execute at runtime that tells me all the routes? I used a jet router, but not all routes work. In rails, you can get a list at runtime.

+4
source share
1 answer

you can get routesin an array using the library below

https://github.com/alansouzati/react-router-to-array

import React from 'react';
import { Route, IndexRoute } from 'react-router';
import reactRouterToArray from 'react-router-to-array';
// or var reactRouterToArray = require('react-router-to-array');

console.log(reactRouterToArray(
<Route path="/" component={FakeComponent}>
{/* just to test comments */}
<IndexRoute component={FakeComponent} />
<Route path="about" component={FakeComponent}>
  <Route path="home" component={FakeComponent} />
  <Route path="/home/:userId" component={FakeComponent} />
</Route>
<Route path="users" component={FakeComponent} />
<Route path="*" component={FakeComponent} />
</Route>)
); //outputs: ['/', '/about', '/about/home', '/users']
+1
source

Source: https://habr.com/ru/post/1652791/


All Articles