reapp-routes
A small library for generating a tree representing routes that also map to paths.
This does two things: saves code and enforces consistency.
Before reapp-routes
var App = ;var Sub = ;var OtherSub = ; moduleexports = <Route handler=App path="/"> <Route name="sub" handler=Sub /> <Route name="otherSub" handler=OtherSub /> </Route>
With reapp-routes
moduleexports =
The routes
method reads in the object tree generated by route
and determines
the path correspondingly. You can even customize it using the dir
property on routes.
In the end, you end up with consistent directory structures that map to your routes,
less requires, less code and a simple routes file.
It does require Webpack or a bundle system that handles dynamic requires.
Examples
Using react-router helpers:
var route routes = ; moduleexports = ;
Rolling your own:
var React = ;var Route DefaultRoute = ;var route routes = ; moduleexports = ; { propschildren = propschildren ? propschildren : null; propshandler = ; return propsdefaultRoute ? <DefaultRoute ...props /> : <Route ...props />;}
Corresponding file tree. Notice how dir
affects nesting:
/components /kitchen Controls.jsx Modals.jsx Popovers.jsx Kitchen.jsx App.jsx
Todo
- Document, tests
See the index.js for more in-code documentation.