项目作者: router5

项目描述 :
Flexible and powerful universal routing solution
高级语言: TypeScript
项目地址: git://github.com/router5/router5.git
创建时间: 2015-06-29T12:28:12Z
项目社区:https://github.com/router5/router5

开源协议:MIT License

下载


Router5

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

Official website: router5.js.org

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
  1. import createRouter from 'router5'
  2. import browserPlugin from 'router5-plugin-browser'
  3. const routes = [
  4. { name: 'home', path: '/' },
  5. { name: 'profile', path: '/profile' }
  6. ]
  7. const router = createRouter(routes)
  8. router.usePlugin(browserPlugin())
  9. router.start()

With React (hooks)

  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3. import { RouterProvider, useRoute } from 'react-router5'
  4. function App() {
  5. const { route } = useRoute()
  6. if (!route) {
  7. return null
  8. }
  9. if (route.name === 'home') {
  10. return <h1>Home</h1>
  11. }
  12. if (route.name === 'profile') {
  13. return <h1>Profile</h1>
  14. }
  15. }
  16. ReactDOM.render(
  17. <RouterProvider router={router}>
  18. <App ></App>
  19. </RouterProvider>,
  20. document.getElementById('root')
  21. )

With observables

Your router instance is compatible with most observable libraries.

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

Examples

Docs