Javascript 如果使用React路由器设置,则React显示路由

Javascript 如果使用React路由器设置,则React显示路由,javascript,reactjs,Javascript,Reactjs,控制台上是否有可以在运行时执行的命令,该命令将告诉我所有路由?我用过react路由器,但这些路由并不都有效。在rails中,您可以在运行时获得一个列表 您可以使用下面的库获取数组中的路由 从“React”导入React; 从“react router”导入{Route,IndexRoute}; 从“react router to array”导入reactRouterToArray; //或var reactRouterToArray=require('react-router-to-arra

控制台上是否有可以在运行时执行的命令,该命令将告诉我所有路由?我用过react路由器,但这些路由并不都有效。在rails中,您可以在运行时获得一个列表

您可以使用下面的库获取数组中的
路由

从“React”导入React;
从“react router”导入{Route,IndexRoute};
从“react router to array”导入reactRouterToArray;
//或var reactRouterToArray=require('react-router-to-array');
控制台日志(reactRouterToArray(
{/*只是为了测试注释*/}
)
); //输出:['/'、'/about'、'/about/home'、'/users']

如果此答案对您有用,您可以将答案标记为正确答案:)
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']