# react-router-with-props

> Extra route functionality react-router-dom

Latest version **2.0.1** (published 2021-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-router-with-props
pnpm add react-router-with-props
yarn add react-router-with-props
bun add react-router-with-props
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-04-05 |
| First published | 2017-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Gonzalo Cañada Benlloch |
| Maintainers | gcbenlloch |
| Keywords | react, router, privateRoute, publicRoute, private, public, routes |

## Links

- npm: https://www.npmjs.com/package/react-router-with-props
- Repository: https://github.com/GonzaloCBenlloch/react-router-with-props
- Homepage: https://github.com/GonzaloCBenlloch/react-router-with-props#readme
- Issues: https://github.com/GonzaloCBenlloch/react-router-with-props/issues
- npm.io page: https://npm.io/package/react-router-with-props

## Dependencies (1)

- [react-router-dom](https://npm.io/package/react-router-dom.md) ^5.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-04-05
- 2.0.0 — 2021-04-05
- 1.0.0 — 2019-05-30
- 0.1.3 — 2018-05-31
- 0.1.2 — 2018-05-31
- 0.1.1 — 2017-10-02

## README

# react-router-with-props

Extra routes for [react-router-dom](https://github.com/ReactTraining/react-router).

### Install

Install it
```
npm i -S react-router-with-props
```

and import it in your file
```
import { PropsRoute, PublicRoute, PrivateRoute } from 'react-router-with-props';
```

### Route types
* *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.

### Props Route
It's the [basic route](https://reacttraining.com/react-router/web/example/basic), 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";

<Route exact path="/">
	<PropsRoute component={Title} text="Hello world!" />
</Route>
```

### Public Route

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";

<Route exact path="/public">
	<PublicRoute authed={false} redirectTo="/admin" component={Title} text="This route is for unauthed users"/>
</Route>
```

And this one will redirect them to '/admin' route.
```js
import { Route } from "react-router-dom";
import { PublicRoute } from "react-router-with-props";

<Route exact path="/public">
	<PublicRoute authed={true} redirectTo="/admin" component={Title} text="This route is for unauthed users"/>
</Route>
```

### Private Route

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";

<Route exact path="/private">
	<PrivateRoute authed={true} redirectTo="/login" component={Title} text="This is a private route"/>
</Route>
```

And this one will call redirect them to '/login' route.
```js
import { Route } from "react-router-dom";
import { PrivateRoute } from "react-router-with-props";

<Route exact path="/private">
	<PrivateRoute authed={false} redirectTo="/login" component={Title} text="This is a private route"/>
</Route>
```

---
_Source: https://npm.io/package/react-router-with-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
