0.15.0 • Published 21 days ago
@nanostores/router v0.15.0
Nano Stores Router
A tiny URL router for Nano Stores state manager.
- Small. 684 bytes (minified and brotlied). Zero dependencies.
- Good TypeScript support.
- Framework agnostic. Can be used with React, Preact, Vue, Svelte, Angular, Solid.js, and vanilla JS.
Since Nano Stores promote moving logic to store, the router is a store, not a component in UI framework like React.
// stores/router.ts
import { createRouter } from '@nanostores/router'
export const $router = createRouter({
home: '/',
list: '/posts/:category',
post: '/posts/:category/:post'
})
Store in active mode listen for <a>
clicks on document.body
and Back button
in browser.
// components/layout.tsx
import { useStore } from '@nanostores/react'
import { $router } from '../stores/router.js'
export const Layout = () => {
const page = useStore($router)
if (!page) {
return <Error404 />
} else if (page.route === 'home') {
return <HomePage />
} else if (page.route === 'list') {
return <ListPage category={page.params.category} filters={page.search} />
} else if (page.route === 'post') {
return <PostPage post={page.params.post} />
}
}
Made in Evil Martians, product consulting for developer tools.
Docs
Read full docs here.
0.15.0
21 days ago
0.14.2
29 days ago
0.14.1
3 months ago
0.14.0
3 months ago
0.13.0
4 months ago
0.12.0
4 months ago
0.12.1
4 months ago
0.10.0
12 months ago
0.11.0
11 months ago
0.9.0
1 year ago
0.8.3
1 year ago
0.9.1
1 year ago
0.8.2
1 year ago
0.8.1
1 year ago
0.8.0
1 year ago
0.7.0
2 years ago
0.5.0
2 years ago
0.4.0
2 years ago
0.6.0
2 years ago
0.3.0
2 years ago
0.3.1
2 years ago
0.2.2
2 years ago
0.2.1
3 years ago
0.2.0
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago