@jcoreio/react-router-apply-middleware

2.0.0 • Public • Published

React Router Apply Middleware

Compose behavior in the render lifecycle of React Router apps.

A name other than "middleware" would be awesome, I just can't think of one. Please suggest.

Installation

npm install react-router-apply-middleware

Usage

import applyRouterMiddleware from 'react-router-apply-middleware'
import { useAsyncProps } from 'react-router-async-props'
import { useRelativeLinks } from 'react-router-relative-links'
import { useNamedRoutes } from 'react-router-named-routes'
import routes from './routes'

const renderWithMiddleware = applyRouterMiddleware(
  useAsyncProps(),
  useRelativeLinks(),
  useNamedRoutes(routes)
)

render(<Router render={renderWithMiddleware} routes={routes}/>, el)

Writing Middleware

For now you'll have to look at the tests, it's a little bit tricky. As soon as the middleware libs I'm working on are updated, I'll come add some notes here about how to do it.

Hopefully we'll end up with stuff like:

useRelay(rootId)
useAlt()
useTransit()
useGroundControl(store)
useScrollBehavior()

etc.

Package Sidebar

Install

npm i @jcoreio/react-router-apply-middleware

Weekly Downloads

1

Version

2.0.0

License

ISC

Last publish

Collaborators

  • gravitate1838
  • manojrsingireddy
  • avramdodson
  • forrest-keller
  • jrmclaurin
  • jedwards1211
  • eladendorf