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

@microsoft/webui-router

v0.0.2

Published

Lightweight client-side router for WebUI apps. Intercepts navigation, matches routes locally or via server route-data, and hydrates components.

Readme

@microsoft/webui-router

Client-side router for WebUI apps with nested route support. Uses the Navigation API to intercept link clicks and loads components on demand — preserving server-rendered content on initial load and fetching JSON partials for subsequent navigations. The server provides the matched route chain; the client does not perform route matching.

How It Works

  1. Server renders the full page — the matched route chain is SSR'd with declarative shadow roots. The page is interactive before JavaScript loads.
  2. Hydration completes — FAST-HTML hydrates shell components.
  3. Router starts — reads the SSR'd active chain and intercepts link clicks via the Navigation API.
  4. Client-side navigation — fetches a JSON partial from the server, which includes the matched route chain. The client diffs old vs new chain and mounts only the changed component. Parent components stay mounted.

No full page reloads. The shell stays in place. Only route content changes.

Installation

npm install @microsoft/webui-router

Quick Start

1. Declare nested routes in index.html:

<body>
  <route path="/" component="app-shell">
    <route path="" component="home-page" exact />
    <route path="users" component="user-list" exact />
    <route path="users/:id" component="user-detail" exact />
  </route>
  <script type="module" src="/index.js"></script>
</body>

Child routes use relative paths (no leading /). The nesting is the route tree.

2. Use <outlet /> in parent components:

<!-- app-shell.html -->
<template shadowrootmode="open">
  <nav>
    <a href="/">Home</a>
    <a href="/users">Users</a>
  </nav>
  <main><outlet /></main>
  <footer>© 2026</footer>
</template>

<outlet /> marks where child route content renders. The nav and footer persist across navigations.

3. Start the router after hydration:

import { TemplateElement } from '@microsoft/fast-html';
import { Router } from '@microsoft/webui-router';

import './app-shell.js';

TemplateElement.options({
  'app-shell': { observerMap: 'all' },
}).config({
  hydrationComplete() {
    Router.start({
      loaders: {
        'home-page': () => import('./pages/home-page.js'),
        'user-list': () => import('./pages/user-list.js'),
        'user-detail': () => import('./pages/user-detail.js'),
      },
    });
  },
}).define({ name: 'f-template' });

Components in loaders are lazy-loaded on first navigation. Components not listed are assumed eagerly loaded.

Nested Routes

Routes nest to any depth. Each parent uses <outlet /> for child content:

<route path="/" component="app-shell">
  <route path="" component="dashboard" exact />
  <route path="settings" component="settings-page">
    <route path="profile" component="profile-page" exact />
    <route path="billing" component="billing-page" exact />
  </route>
</route>

Navigating from /settings/profile to /settings/billing only remounts the billing component — app-shell and settings-page stay mounted with their state preserved.

The exact Attribute

  • Leaf routes (no children): add exact
  • Parent routes (have <outlet />): omit exact

Without exact, a route matches any URL that starts with its path — which is what parent routes need.

API

Router.start(config?)

Start the router. Call after hydration completes.

| Option | Type | Description | |--------|------|-------------| | basePath | string | Prefix for all route URLs (e.g., "/app") | | loaders | Record<string, () => Promise<unknown>> | Lazy-loading map: component tag → dynamic import |

Router.navigate(path)

Programmatic navigation:

Router.navigate('/users/42');

Router.back()

Navigate back in history.

Router.activeComponent

Component tag of the active leaf route:

console.log(Router.activeComponent); // "user-detail"

Router.activeParams

Bound parameters from all nesting levels:

console.log(Router.activeParams); // { id: "42" }

Router.destroy()

Tear down the router and remove event listeners.

Navigation Event

Dispatched on window after each navigation:

window.addEventListener('webui:route:navigated', (e) => {
  const { component, params, path } = (e as CustomEvent).detail;
  console.log(`Navigated to ${component}`, params);
});

Route Path Syntax

| Pattern | Example | Matches | |---------|---------|---------| | literal | users | Exact segment | | :param | users/:id | Captures segment → { id: "42" } | | :param? | search/:query? | Optional segment | | *splat | files/*path | Rest of path → { path: "a/b/c" } |

Paths are relative to the parent route. Use / prefix only for the root route.

Server Contract

On client-side navigation, the router sends:

GET /users/42
Accept: application/json
X-WebUI-Inventory: <hex bitmask>

The server should return:

  • Accept: application/json → JSON partial: { state, templates, inventory, path, chain } — returned directly from renderPartial(), no assembly required
  • Otherwise → Full SSR'd HTML page (handler emits a <meta name="webui-inventory"> tag in <head> so the client knows which templates are loaded)

The chain field contains the matched route chain — the client uses it to diff against the previous chain and only remount what changed. The X-WebUI-Inventory header is a bitmask of component templates the client already has — the server uses it to avoid sending duplicate templates.

See the Routing guide for complete server implementation examples.

License

MIT