react-relative-routes
A wrapper around react-router components to allow easy way of routes configuration.
Features
- Unopinionated routes configuration with well know path strings
- Wrappers around the react-router components to support patterns
- Well tested library
Installation
yarn add react-relative-routes
or
npm install react-relative-routes --save
Basic usage
Configure routes
import PathPattern from 'react-relative-routes'; const BASE_PATTERN = PathPattern;const ABOUT_PATTERN = BASE_PATTERN;const USER_PROFILE_PATTERN = BASE_PATTERN;
Declare routes switch
import RelativeSwitch from 'react-relative-routes'; const Dashboard = <RelativeSwitch> <RelativeRoute = = /> <RelativeRoute = = /> <RelativeRoute = = /> </RelativeSwitch>;
Use RelativeLink and RelativeNavLink
import RelativeLink RelativeNavLink from 'react-relative-routes'; const Links = <div> <RelativeNavLink ="active" => About </RelativeNavLink> <RelativeLink = => Go to user </RelativeLink> </div>;
FAQ
<RelativeSwitch />
instead of react-router's Switch?
Why custom <Switch />
does not work with custom <Route />
components. Since we need to use
custom props for passing the pattern there is a need to use <RelativeLink />
or <RelativeNavLink />
.
Typings
If you are using TypeScript, you don't have to install typings - they are provided in npm package.
License
MIT