
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@altafonte/router
Advanced tools
This package is a fork of @sethealth/router which is a fork of Stencil Router V2, an experimental new router for stencil that focus in:
push function accepts a second param as options, where you can tell to replace, so it uses history.replaceState instead history.pushState. This is intended to be used on automatic redirections, so you don't break the back/forward feature on navigators.Router.replace(url) is a shortcut for Router.push(url, { replace: true })This router backs up the document.location in a @stencil/store, this way we can respond to changes in document.location is a much simpler, way, not more subscribes, no more event listeners events to connect and disconnect.
Functional Components are the used to collect the list of routes, finally the Switch renders only the selected route.
npm install @altafonte/router
import { createRouter, Route } from '@altafonte/router';
const Router = createRouter();
@Component({
tag: 'app-root',
})
export class AppRoot {
render() {
return (
<Host>
<Router.Switch>
<Route path="/">
<h1>Welcome<h1>
<p>Welcome to the new stencil-router demo</p>
</Route>
<Route path={/^\/account/}>
<app-account></app-account>
</Route>
</Router.Switch>
</Host>
);
}
}
<Host>
<Router.Switch>
<Route path="/" to="/main"/>
<Route path={/^account/} to="/error"/>
</Router.Switch>
</Host>
<Host>
<Router.Switch>
<Route path={match("/colors/:type")} render={({ type }) => {
if (!["black", "white"].includes(type)) {
return Router.push("/colors/black", { replace: true })
}
return <valid-color-component color={type}/>
}}/>
</Router.Switch>
</Host>
Route can take an optional render property that will pass down the params. This method should be used instead of JSX children.
Regex or functional matches have the chance to generate an object of params when the URL matches.
import { createRouter, Route, match } from '@altafonte/router';
const Router = createRouter();
<Host>
<Router.Switch>
<Route
path={/^acc(ou)nt/}
render={(params) => (
<p>{params[1]}</p>
)}
/>
<Route
path={match('/blog/:page')}
render={({page}) => <blog-post page={page}>}
/>
<Route
path={(url) => {
if (url.includes('hello')) {
return {user: 'hello'}
}
return undefined;
}}
render={({user}) => (
<h1>User: {user}</h1>
)}
/>
</Router.Switch>
</Host>
The href() function will inject all the handles to an native anchor, without extra DOM.
import { createRouter, Route, href } from '@altafonte/router';
const Router = createRouter();
<Host>
<Router.Switch>
<Route path="/main">
<a {...href('/main')} class="my-link">Go to blog</a>
</Route>
<Route path="/blog">
<a {...href('/main')}>Go to main</a>
</Route>
</Router.Switch>
</Host>
@Component({
tag: 'app-root',
})
export class AppRoot {
@State() logged = false;
render() {
return (
<Host>
<Router.Switch>
{this.logged && (
<Route path="/account">
<app-account></app-account>
</Route>
)}
{!this.logged && (
<Route path="/account" to="/error"/>
)
</Router.Switch>
</Host>
);
}
}
Because the router uses @stencil/store its trivial to subscribe to changes in the locations, activeRoute, or even the list of routes.
import { createRouter, Route } from '@altafonte/router';
const Router = createRouter();
@Component({
tag: 'app-root',
})
export class AppRoot {
componentWillLoad() {
Router.onChange('url', (newValue: InternalRouterState['url'], _oldValue: InternalRouterState['url']) => {
// Access fields such as pathname, search, etc. from newValue
// This would be a good place to send a Google Analytics event, for example
});
}
render() {
const activePath = Router.state.activeRoute?.path;
return (
<Host>
<aside>
<a class={{'active': activePath === '/main'}}>Main</a>
<a class={{'active': activePath === '/account'}}>Account</a>
</aside>
<Router.Switch>
<Route path="/main">
<h1>Welcome<h1>
<p>Welcome to the new stencil-router demo</p>
</Route>
<Route path='/account'>
<app-account></app-account>
</Route>
</Router.Switch>
</Host>
);
}
}
The routes state includes:
url: URL;
activeRoute?: RouteEntry;
urlParams: { [key: string]: string };
routes: RouteEntry[];
FAQs
This is a fork of @sethealth/router, which forks stencil-router-v2
We found that @altafonte/router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.