navigation-router
v0.1.0
Published
Client-side router built on the Navigation API and URLPattern
Maintainers
Readme
navigation-router
Client-side router for vanilla TypeScript apps, built on the Navigation API and URLPattern.
Install
pnpm add navigation-routerOptional types for the Navigation API:
pnpm add -D navigation-api-typesFeatures
- Class-based routes with
setup/render/unmount - Typed
paramsandqueryviaRouteCtx - Pluggable adapters: Navigation, Hash, Memory
- Optional built-in nav UI, or
createLink+getRoutes - Race-safe async
setup,onNotFound,refresh(),destroy() - Zero runtime dependencies
Quick start
import {
createRouter,
NavigationAdapter,
RouteComponent,
type RouteCtx,
} from 'navigation-router'
class HomeRoute extends RouteComponent {
constructor() {
super({ path: '/', label: 'Home' })
}
render(_ctx: RouteCtx) {
const el = document.createElement('section')
el.textContent = 'Home'
return el
}
}
const router = createRouter({
adapter: new NavigationAdapter(),
routes: [HomeRoute],
renderRoot: () => document.querySelector('#app'),
})Development
pnpm install
pnpm dev # playground
pnpm docs:dev # VitePress docs
pnpm test # Vitest
pnpm build:lib # emit dist/ for publishPublish
- Bump
versioninpackage.json - Commit and push to
master - Create a GitHub Release with tag
vX.Y.Zmatching that version
CI runs .github/workflows/publish.yaml on release and publishes to npm with provenance.
Requires repository secret NPM_TOKEN (Automation or Publish token from npmjs.com).
Scripts
| Script | Description |
| --- | --- |
| pnpm dev | Playground (Vite) |
| pnpm build:lib | Build publishable dist/ |
| pnpm build:playground | Build playground |
| pnpm build:site | Docs + playground → site/ (GitHub Pages) |
| pnpm build | Typecheck + lib + playground |
| pnpm test | Unit tests |
| pnpm docs:dev | Documentation site |
| pnpm lint | ESLint |
Project layout
src/ library source
dist/ published build output
playground/ interactive demo
docs/ VitePress documentation
tests/ Vitest suiteDocumentation
- Local:
pnpm docs:dev - Guide: docs/guide/getting-started.md
License
MIT
