/directory-react-routes

Simple module that translate a directory from a webpack-context to react-router routes.

Primary LanguageJavaScriptMIT LicenseMIT

directory-react-routes

Simple module that translate a directory from a webpack-context to react-router routes.

Eg: a file with the following path: c:/dev/pages/directory/test.jsx where you start your context in: c:/dev/pages/ will get you the route: directory/test

Install

npm install directory-react-routes

Arguments

context

A webpack context, the directory which this context is initiated in will be used as base when building the routes.

filter

A function that will get the component which is about to be added to the route as argument. If the function returns false the component will not be added to the resulting list of routes.

props

A object from whose props all the resulting ruotes will inherit from. Useful if you would like to inject something as a onLoad etc.

Example

var directoryRoutes = require('directory-react-routes');

var context = require.context('./pages/', true, /^(.*\.(jsx$))[^.]*$/igm)

var routes = directoryRoutes(context, function(route) { return route.doAdd }, { onEnter: function() { alert("routed!") } })


<Router>
  {routes}
</Router>