history-router
This is a Router with history .
Installation
npm install --save history-router
Basic usage
import HistoryRouter from ' history-router'
const router = new HistoryRouter ()
/** Route '/user' with parameters */
router .when (' /user/:id' , ({ params }) => {
// 32
console .log (params .id )
})
/** https://github.com/ReactTraining/history */
router .history .push (' /user/32' )
Properties
Methods
HistoryRouter(hash: Boolean = true)
Create HistoryRouter Instance.
Name
description
hash
Using hash mode
const router = new HistoryRouter (false )
HistoryRouter.when(path: string, callback: Function, middlewares: Array = []): void
Register a new Route .
Callback Parameters
/** Route '/user' with parameters */
router .when (' /user/:id' , ({ from, to, params, response }) => {
/**
* response => 'Hello, world'
*/
console .log (response)
},
[
/** Route middleware */
({ from, to, response }) => {
return ' Hello, world'
}
])
HistoryRouter.middleware(callback: Function): void
Register a Global middleware .
Name
description
callback
Global middleware callback
Callback Parameters
/** Global middleware */
router .middleware (({ from, to, response }) => {
return ' Hello, world'
})
router .middleware (({ from, to, response }) => {
/**
* response => 'Hello, world'
*/
return response
})
License
MIT
Copyright 2018-2020. SangWoo Jeong . All rights reserved.