0.16.1 • Published 9 months ago

@nanostores/router v0.16.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Nano Stores Router

A tiny URL router for Nano Stores state manager.

  • Small. 712 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 at Evil Martians, product consulting for developer tools.


Docs

Read full docs here.

0.16.0

9 months ago

0.16.1

9 months ago

0.15.1

11 months ago

0.15.0

1 year ago

0.14.2

1 year ago

0.14.1

1 year ago

0.14.0

1 year ago

0.13.0

1 year ago

0.12.0

1 year ago

0.12.1

1 year ago

0.10.0

2 years ago

0.11.0

2 years ago

0.9.0

2 years ago

0.8.3

2 years ago

0.9.1

2 years ago

0.8.2

2 years ago

0.8.1

2 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.6.0

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago