🐁 react-tiniest-router
For the times when you really need a simple router.
Based on mobx-router and rttr.
Usage
- Write the routes object.
const routes = home: id: 'home' path: '/' about: id: 'about' path: '/about' gallery: id: 'gallery' path: '/gallery/:imageId'
- Wrap your app with the Router component
<Router routes=routes> <App /></Router>
- Use the router using
useRouter
- Use the
goTo
function for navigating to a route - Use the
isRoute
function for checking if a route is currently active
const Root = { const goTo isRoute = ; return <div> <div> <button onClick= >go home</button> <button onClick= >go to about</button> <button onClick= > go to picture 1 </button> <button onClick= > go to picture 2 </button> <button onClick= > go to picture 3 </button> </div> <br/> && <div>Welcome home</div> && <div>About us</div> && <Gallery /> </div> ;};
- You also get
params
,queryParams
,routeId
,path
in the router object.
const Gallery = { const params = ; return <div>Browsing picture paramsimageId</div>;};
FAQ
-
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
@thekitze
🙋♂️ Made by- 🏫 React Academy - Interactive React and GraphQL workshops
- 💌 Twizzy - A standalone app for Twitter DM
- 🤖 JSUI - A powerful UI toolkit for managing JavaScript apps
- 📹 Vlog - Watch my sad developer life