Extra route functionality react-router-dom
npm install react-router-with-props
npm i -S react-router-with-props
`
and import it in your file
`
import { PropsRoute, PublicRoute, PrivateRoute } from 'react-router-with-props';
`
$3
PropsRoute* - Default route to which you can pass props.
PublicRoute* - It prevents the access to auth users and you can pass props to it.
PrivateRoute* - It prevents the access to unauth users and you can pass props to it.
$3
It's the basic route, but you can pass props to it like to any other component.
Any one can access it.
`js
import { Route } from "react-router-dom";
import { PropsRoute } from "react-router-with-props";
`
$3
It requires two extra props.
| Prop | Type | |
|---|---|---|
| authed | boolean | If the user is authed or not |
| redirectTo | string | route to redirect if necessary |
Only unauthed users can access it.
The next exemple will call the Title component and will pass to it the text prop.
`js
import { Route } from "react-router-dom";
import { PublicRoute } from "react-router-with-props";
`
And this one will redirect them to '/admin' route.
`js
import { Route } from "react-router-dom";
import { PublicRoute } from "react-router-with-props";
`
$3
It requires two extra props.
| Prop | Type |---|
| ------ | ------ | ------ |
| authed | boolean | If the user is authed or not |
| redirectTo | string | route to redirect if necessary |
Only authed users can access it.
The next exemple will call the Title component and will pass to it the text prop.
`js
import { Route } from "react-router-dom";
import { PrivateRoute } from "react-router-with-props";
`
And this one will call redirect them to '/login' route.
`js
import { Route } from "react-router-dom";
import { PrivateRoute } from "react-router-with-props";
``