react-router-to-array

Convert your react router component to an array with all static routes

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
react-router-to-array
9400.1.36 years ago7 years agoMinified + gzip package size for react-router-to-array in KB

Readme

react-router-to-array
Convert your react router component to an array with all static routes. Dynamic routes and their corresponding nested static routes are ignored. No match () route is also ignored. See usage example below.
Build Status

Install

npm install react-router-to-array

Usage

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']

Use case

I wrote this library mainly to use in conjuction with static-site-generator-webpack-plugin

License

MIT