npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bunnix/router

v0.9.0

Published

Bunnix Router: decentralized, context-aware routing for Bunnix

Readme

Bunnix Router

A decentralized, context-aware routing solution for the Bunnix framework.

Key Features

  • Route Groups: Organize routes with shared policies and layouts.
  • Policies: Centralize guard logic with RoutePolicy.
  • Scoped Navigation: Navigation is injected into components and layouts.
  • Dynamic Parameters: Parse URL segments like :id automatically.
  • Layout Support: Persistent layouts with routerOutlet.

Bootstrap

To enable routing, you must wrap your root component in the BrowserRouter when calling the render function.

import Bunnix from '@bunnix/core';
import { BrowserRouter } from '@bunnix/router';
import App from './App.js';

Bunnix.render(
    <BrowserRouter>
        <App />
    </BrowserRouter>,
    document.getElementById('root')
);

Example Usage

Setting up the Router

import Bunnix from '@bunnix/core';
import { RouterRoot, RouteGroup, Route, Link } from '@bunnix/router';

const App = () => (
    <RouterRoot>
        <RouteGroup root layout={AppLayout}>
            <Route path="/" component={Home} />
            <Route path="/user/:id" component={UserProfile} />
        </RouteGroup>
        <Route notFound component={NotFound} />
    </RouterRoot>
);

Router Context Helper

import { useRouterContext } from '@bunnix/router';

const appContext = useRouterContext({
    user: null,
    permissions: []
});

Policies

Policies run before rendering and can redirect.

import { RouterRoot, RouteGroup, RoutePolicy, Route } from '@bunnix/router';

const App = () => (
    <RouterRoot>
        <RouteGroup rootPath="/account">
            <Route path="/account" component={Account} />
            <RoutePolicy handler={({ context, navigation }) => {
                if (!context.user) navigation.replace('/login');
            }} />
        </RouteGroup>
    </RouterRoot>
);

Layouts & Router Outlet

Layouts allow you to wrap your routes with persistent UI (like navbars or sidebars). A layout component receives two special props: routerOutlet and navigation.

import { Link } from '@bunnix/router';

/**
 * @param {Function} props.routerOutlet - A function that returns the matched route content.
 * @param {Object} props.navigation - The scoped navigation object.
 */
function AppLayout({ routerOutlet, navigation }) {
    return Bunnix('div', { class: 'layout' }, [
        Bunnix('nav', [
            Link({ to: '/', navigation }, 'Home'),
            Link({ to: '/form', navigation }, 'Form')
        ]),
        Bunnix('main', [
            // Call the outlet to render the matched route component
            routerOutlet()
        ])
    ]);
}

With vs Without Layout

  • With Layout: The RouteGroup renders the layout component. The matched route is not visible until you call props.routerOutlet() inside the layout's VDOM.
  • Without Layout: The matched route component renders directly as its only content.

Consuming Navigation

Matched components and layouts receive the navigation object.

function Home({ navigation }) {
    return Bunnix('div', [
        Bunnix('h1', 'Home Page'),
        Bunnix('button', { 
            click: () => navigation.push('/user/123') 
        }, 'View User')
    ]);
}

Navigation Object Reference

  • navigation.push(path): Navigates to a new URL.
  • navigation.replace(path): Replaces the current history entry.
  • navigation.back(fallback?): Goes back in history or to the fallback (defaults to rootPath).
  • navigation.path: Current path string.
  • navigation.params: Current route params.
  • navigation.group.rootPath: Current group root path.

Components

  • BrowserRouter: The root container for your routing tree.
  • RouterRoot: Defines the router tree.
  • RouteGroup: Defines grouped routes with layouts and policies.
  • RoutePolicy: Guards for group routes.
  • Link: A helper component for declarative navigation: Link({ to: '/path', navigation }, 'Label').