Have ideas to improve npm?Join in the discussion! »

router5TypeScript icon, indicating that this package has built-in type declarations

6.1.3 • Public • Published

npm version Build Status Join the chat at https://gitter.im/router5/router5 styled with prettier

Official website: router5.github.io

router5

router5 is a framework and view library agnostic router.

  • view / state separation: router5 processes routing instructions and outputs state updates.
  • universal: works client-side and server-side
  • simple: define your routes, start to listen to route changes
  • flexible: you have control over transitions and what happens on transitions
import createRouter from 'router5'
import browserPlugin from 'router5/plugins/browser'
 
const routes = [
    { name: 'home', path: '/' },
    { name: 'profile', path: '/profile' }
]
 
const router = createRouter(routes)
    .usePlugin(browserPlugin())
 
router.start()

With React (new context API)

import React from 'react'
import ReactDOM from 'react-dom'
import { RouteProvider, Route } from 'react-router5'
 
function App({ route }) {
    if (!route) {
        return null
    }
 
    if (route.name === 'home') {
        return <h1>Home</h1>
    }
 
    if (route.name === 'profile') {
        return <h1>Profile</h1>
    }
}
 
ReactDOM.render(
    <RouteProvider router={router}>
        <Route>{({ route }) => <App route={route} />}</Route>
    </RouteProvider>,
    document.getElementById('root')
)

With observables

Your router instance is compatible with most observable libraries.

import { from } from 'rxjs/observable/from'
 
from(router).map(({ route }) => {
    /* happy routing */
})

Guides

"Past and future of client-side routing" @ ReactiveConf 2016

Integrations

API

Install

npm i [email protected]

Version

6.1.3

License

MIT

Unpacked Size

228 kB

Total Files

94

Last publish

Collaborators

  • avatar