react-router-pls
v0.0.2
Published
A thin wrapper around React Router.
Downloads
2
Maintainers
Readme
React Router Pls
A thin wrapper around React Router that adds:
✓ A Hook
✓ Query parameter support
Motivation
At work, I need to create a large number of small React applications. I use the same React Router configuration in all of them. Rather than continue copy and pasting the code, I created this library.
If you are building a single app, then this library could still be useful to you. It may be preferable to copy and paste the source code rather than installing this as a dependency, though.
Installation
Install using npm:
npm install react-router-pls
or yarn:
yarn add react-router-pls
Getting Started
Configuring a Router
Use the Router
export from this library instead of the one from React Router.
import { Router } from 'react-router-pls';
export default function App() {
return (
<Router>
<AppContents />
</Router>
);
}
Using the useRouter
Hook
Use the useRouter
Hook in your components.
import { useRouter } from 'use-router';
export default function MyComponent() {
const { match, location, history } = useRouter();
}
The values returned by the Hook are the same as the Route props from React Router.
Using query parameters
This library has a more opinionated approach to query parameters than React Router. This will be documented soon.
Other functionality
For everything else, refer to the React Router docs.