React Hook Router
The modern alternative to react-router.
React 16.8.1 upwards.
How to install
Well, this is straightforward:
npm i hookrouter
This project is not and will not be written in typescript.
Thanks to the github user @mcaneris, you can install types via:
npm i @types/hookrouter
I did not check if those types are correct nor will I keep them up to date with future releases.
Detailed documentation about how to use hookrouter can be found here
A quick example
import useRoutes from 'hookrouter';const routes =<HomePage /><AboutPage /><ProductOverview /><ProductDetails = />;const MyApp =const routeResult = ;return routeResult || <NotFoundPage />;
Routes are defined as an object. Keys are the routes, which are matched
against the URL, the values need to be functions that are called when a route
matches. You may define placeholders in your routes with
will be forwarded as props to your function calls so you can distribute them
to your components.
The hook will return whatever the route function returned, so you may also return strings, arrays, React fragments, null - whatever you like.