react-router-hooks-patch
Patch react-router's Route components with static hook methods
onEnter
/onLeave
.
Install
npm install react-router-hooks-patch --save
Usage
patchRouteHooks(Route: <Route>, data: ?Object)
;
Route
- Route or array or Routes which component you want to patch with staticonEnter
/onLeave
methods. Children routes will be patched too.data
- pass data that you need in your methods. It's perfect place for instances of some sort of data abstraction (e.g. Flux/Redux in universal apps). **Passed data object will be the first argument inonEnter
/onLeave
functions.
Requirements
Patch works only with latest react-router version (>= 2
, see upgrade guide);
Example
;;;;; // or any data abstraction Component static { // do some async actions and call done when you're ready ; } static { // receives only passed data object as argument } { return <div>...</div>; } const routes = <Route path="/" component=App> <Route path="about" component=About onEnter= { // methods on Route also get patched } /> <Route path="users" component=Users /> </Route>; const flux = ;const patchedRoutes = ; ReactDOM;
NOTE: You can check the detailed application example with server-rendering and patching routes in this repo.
MIT Licensed