0.2.4 • Published 4 years ago

@peajs/router v0.2.4

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

@peajs/router

Installation

npm i @peajs/router

Usage

import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Link } from '@peajs/router'

const Home = () => (
  <div>
    <Link to="/">Home</Link>
    <Link to="/about">About</Link>
    <h1>Home</h1>
  </div>
)

const About = () => (
  <div>
    <Link to="/">Home</Link>
    <Link to="/about">About</Link>
    <h1>About</h1>
  </div>
)

const NotFound = () => <div>404 not found</div>

const routes = [
  {
    path: '/',
    component: Home,
  },
  {
    path: '/about',
    component: About,
  },
  {
    path: '**',
    component: NotFound,
  },
]

const App = () => <Router routes={routes} />

ReactDOM.render(<App />, document.getElementById('root'))

Interceptor

import { navigate, intercept } from '@peajs/router'

intercept((ctx, next) => {
  if (ctx.to === '/') {
    navigate('/dashboard')
  } else {
    return next()
  }
})

License

MIT License

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago