
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
poptart-router
Advanced tools
Some JavaScript client-side router.
With npm do:
npm install poptart-router history --save
You also need the history
module.
var createRouter = require('poptart-router')
var history = require('history')()
var router = createRouter(history)
function callback (location, next) {
// That is history's location object
// https://github.com/ReactJSTraining/history/blob/master/docs/Location.md
var name = location.params.name; // url params
var foo = location.state.foo; // your state object
console.log(name)
console.log(foo)
next() // allow the callback chain go forward
}
router.add('/hello/:name', callback)
router.start()
router.push({
pathname: router.generate('/hello/:name', { name: 'world' })
state: { foo: 'bar' }
})
// => "world"
// => "bar"
createRouter(history[, base, callback])
history
A history object.base
(String) should be set in case you're not operating at the root path /
of the domain.callback
is fired after all callbacks of every matched route have been called. It should follow this signature function (err, location) {}
.router.add(path[, callback...])
You can add as many callbacks as you need. This is internally handled by the ware
module, so the callback signature should be the following:
function (location, next) {}
Remember to call next
when you're done so the next callback in line can be fired.
Routes are matched in the order they were add
ed, and they are matched using the famous path-to-regexp
module, used by Express among many others, so regular expressions are supported and all that.
Please check out the path-to-regexp
documentation to know more about route options. Also checkout the live demo!
add
alias.
router.start([immediately])
Router starts listening for route changes.
For immediately
pass false
if you want to skip parsing the current location at start
.
router.push(location)
A wrapper around history.push
, where location
is that one from the history
module.
This will update the browser's URL and fire any callbacks.
router.replace(location)
Same as push
but using replaceState
...
router.stop()
Stop listening for changes.
MIT
FAQs
Client-side router.
The npm package poptart-router receives a total of 0 weekly downloads. As such, poptart-router popularity was classified as not popular.
We found that poptart-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.