
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
Yet Another Browser Router, or YABR for short. For those that want a simple, easy-to-understand client-side URL router.
Yet Another Browser Router, or YABR for short. For those that want a simple, easy-to-understand client-side URL router.
I know, I know, there are a million different ways to handle client-side URL routing for making a responsive, single-page application. For me, a lover of all things ReactJS, I was offput by the way React Router conflated UI components with URLs and browser history. To me, those seemed like incompatible items. I also wanted to react (no pun intended) when a route was entered or exited, yet I hadn't found a routing solution that made me happy. Enter yabr.
npm install yabr --save
const router = require('yabr');
router.init({
'/user/:userId': {
onEnter({ params, router }) {
const { userId } = params;
if (!db.userExists(userId)) {
// User didn't exist, let's just go back to the index
router.navigate('/');
} else {
const history = db.fetchUserHistory(userId);
// TODO: Do some more stuff
}
},
onExit() {
alert('Leaving user editor');
}
},
'/': {
onEnter({ query }) {
console.log('Hey, I am an index route with a querystring of ${query}');
},
},
});
init(routes, onchange, useBrowserHistory = false)
routes - Object - Routes object, where the key is the route, in any format that is accepted by the path-to-regexp format (which is famously used by Express). The value of the key-value pair is an object that accepts three properties:
onEnter({ pathname, query, params, router }, ...injectedParams)
pathname, query object, route params object, and current instance of router. Optionally, additional injected params are provided to the function, if these have been configured via the inject property (listed below).onExit({ router }, ...injectedParams)
router is provided, as well as an optional injected set of params, if they've been configured with the inject property.inject - Array
onEnter and onExit functions. Useful if you want to keep your routes definitions in a separate module for better organization. Helps to avoid monolithic, massive JS files containing a ton of application logic.
router.init({
'/user/:userId`: {
onEnter({ params }, db, config) {
const results = db.query(config.userQuery);
},
inject: [ db, config ],
},
});
onchange - Function - Defaults to undefined
Object as its argument, containing the pathname and search of the URL.router.init({ /* my routes here */ }, ({ pathname, search }) => {
console.log(`URL path has changed to ${pathname}`);
console.log(`Query string is now ${search}`);
});
useBrowserHistory - Boolean - Defaults to false
true, uses the HTML5 Browser History API to handle the URL routing. Defaults to false, which causes Hash History to be used instead.
start()
start() is called.navigate(url, query, merge = false)
url - String
query - String or Object
merge - Boolean - Defaults to false
true, attempts to merge the incoming query with the current query present in the browser's URL.appendQuery(query, merge = false)
query - Object
merge - Boolean - Defaults to false
true, merges the query object you provide with the existing query string that is present in the current URL.updatePropInQuery(prop, val)
prop - String - String name of the query property to updateval - String or Number - Value that will replace the current value
removePropFromQuery(prop)prop - String - Property to be removed from the query string.FAQs
Yet Another Browser Router, or YABR for short. For those that want a simple, easy-to-understand client-side URL router.
We found that yabr 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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.