
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
@axtk/router
Advanced tools
Core ideas:
window.location
(route.href
, route.assign()
, route.replace()
).// route.js
import {Route} from '@axtk/router';
export const route = new Route();
Adding a handler of an exact URL path:
import {route} from './route';
let routeListener = route.addListener('/home', ({href}) => {
console.log(href);
});
of a specific URL path pattern:
route.addListener(/^\/section\/(?<id>\d+)\/?$/, ({href, params}) => {
console.log(href, params.id);
});
and removing a previously created route listener:
routeListener.remove();
Tracking all route changes:
let unsubscribe = route.onChange(({href}) => {
console.log(href);
});
and unsubscribing from them:
unsubscribe();
Checking a route pattern (or an array thereof) if it matches the current path:
// Provided that the current location is '/section/42':
route.match('/home'); // null
route.match('/section/42'); // {}
route.match(/^\/section\/(?<id>\d+)\/?$/); // {0: '42', id: '42'}
Getting the current location:
console.log(route.href);
Changing the current location:
// With the current location saved in the browser history
route.assign('/home');
// Without saving the current location in the browser history
route.replace('/home');
Reloading the current location (by re-dispatching the current location event to the subscribers of route
):
route.reload();
Jumping to browser history entries:
route.go(-2); // to go 2 entries back in the browser history
route.back(); // = route.go(-1);
route.forward(); // = route.go(+1);
The interaction of a Route
instance with window.history
or window.location
is isolated in a couple of methods that can be overriden in descendant classes to apply custom routing behavior. These methods are: init
, transition
, go
, calcHref
.
For example: by default, a Route
instance takes into account changes in the pathname
, search
, and hash
portions of the URL combined. To make a Route
instance disregard the URL search
and hash
, the Route
class can be extended to redefine the calcHref
method:
import {Route, getPath} from '@axtk/router';
export class PathRoute extends Route {
calcHref(location) {
return getPath(location, {search: false, hash: false});
}
}
FAQs
A lightweight browser history router
The npm package @axtk/router receives a total of 21 weekly downloads. As such, @axtk/router popularity was classified as not popular.
We found that @axtk/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
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.