React Router: get all routes as array

后端 未结 3 1314
无人及你
无人及你 2021-01-04 03:36

Is there an existing library that will reduce my route instance to an array of paths?

Example:

    

        
3条回答
  •  孤街浪徒
    2021-01-04 03:49

    As I did not find anything, I ended up creating a library for that...

    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(
      
        {/* just to test comments */}
        
        
          
          
        
        
        
      )
    ); //outputs: ['/', '/about', '/about/home', '/users']
    

提交回复
热议问题