Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
poptart-router
Advanced tools
JavaScript client-side router.
With npm do:
npm install acstll/poptart history --save
you see this is not on the npm registry yet.
You also need the history
module.
var createRouter = require('poptart-router')
var history = require('history')()
var router = createRouter(history)
function callback (obj, next) {
var name = obj.params.name; // url params
var foo = obj.location.state.foo; // your state object
// history's location object is available
// http://rackt.github.io/history/stable/Location.html
console.log(name)
console.log(foo)
next() // allow the next callback to fire
}
router.add('hello', '/hello/:name', callback)
router.start()
router.navigate('hello', { 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, obj) {}
.router.add(name, 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 (obj, 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 (pretty useful)!
add
alias.
router.start()
Router starts listening for route changes.
router.navigate(name[, params, options])
name
The route nameparams
Object…Options being:
state
: Object. The state you want to keep in History for that path.replace
: Boolean. Call replaceState
instead of pushState
on history
. (Default: false).This will update the browser's URL and fire any callbacks.
router.stop()
Stop listening for route changes.
MIT
FAQs
Client-side router.
The npm package poptart-router receives a total of 1 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.