# Nano Stores Router

> A tiny router for the Nano Stores state manager

- URL: https://evilmartians.com/opensource/nano-stores-router
- GitHub: https://github.com/nanostores/router
- Authors: Andrey Sitnik, Dan Kozlov

---

Nano Stores is a tiny router for the [Nano Stores](https://evilmartians.com/opensource/nano-stores) state manager.

* **Small.** 836 bytes (minified and gzipped). Zero dependencies. It uses [Size Limit](https://evilmartians.com/opensource/size-limit) to control size.
* Good **TypeScript** support.
* Framework agnostic; can be used with **React**, **React Native**, **Preact**, **Vue**, **Svelte**, **Solid**, **Lit**, **Angular**, and vanilla JS.

Since Nano Stores promotes moving logic to the store, the router is a store, not a component in a UI framework like React.

```ts
// stores/router.ts
import { createRouter } from '@nanostores/router'

export const router = createRouter({
  home: '/',
  category: '/posts/:categoryId',
  post: '/posts/:categoryId/:id'
} as const)
```

In active mode, the store listens for `<a>` clicks on `document.body` and the Back button in the browser.

```tsx
// components/layout.tsx
import { useStore } from '@nanostores/react'

import { router } from '../stores/router.js'

export const Layout = () => {
  const page = useStore(router)

  if (!page) {
    return 
  } else if (page.route === 'home') {
    return 
  } else if (page.route === 'category') {
    return 
  } else if (page.route === 'post') {
    return 
  }
}
```
