For the times when you *really* need a simple router. Based on [mobx-router](https://github.com/kitze/mobx-router) and [rttr](https://github.com/kitze/rttr).
npm install react-tiniest-routerFor the times when you really need a simple router.
Based on mobx-router and rttr.
1. Write the routes object.
``js`
const routes = {
home: {
id: 'home',
path: '/',
},
about: {
id: 'about',
path: '/about',
},
gallery: {
id: 'gallery',
path: '/gallery/:imageId',
},
}
2. Wrap your app with the Router component
`js`
3. Use the router using useRouter
- Use the goTo function for navigating to a routeisRoute
- Use the function for checking if a route is currently active
`js
const Root = () => {
const {goTo, isRoute} = useRouter();
return (
{isRoute(routes.home) &&
4. You also get
params, queryParams, routeId, path in the router object.`js
const Gallery = () => {
const { params } = useRouter();
return Browsing picture {params.imageId};
};
``---
- Does it support optional parameters in the path definition?
Not yet, but it will as soon as I need them in a project.
- Does it support SSR?
No.
- Will it ever support SSR?
NO.
- Does it have tests?
TypeScript is poor man's tests.
- Will it ever have tests?
If you write them.
- Does it support code splitting?
Did you see which repo you're actually browsing?
Does it say "facebook" in the url? No. So, no.
- Does it support async routes?
Please stop doing stupid stuff with your router.
- Does it support protected routes?
Please stop doing stupid stuff with your router.
- I'm offended by this FAQ section, where can I complain?
Yell @ me on Twitter