# @rq/react-easy-router

> Easy and lightweight react router

Latest version **3.2.2** (published 2023-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rq/react-easy-router
pnpm add @rq/react-easy-router
yarn add @rq/react-easy-router
bun add @rq/react-easy-router
```

## 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 | 3.2.2 |
| Published | 2023-03-11 |
| First published | 2018-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 37.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Oleg Pudeyev |
| Maintainers | rq |
| Keywords | react, router, lightweight, small |

## Links

- npm: https://www.npmjs.com/package/@rq/react-easy-router
- Repository: https://github.com/p/react-easy-router
- Homepage: https://github.com/p/react-easy-router#readme
- Issues: https://github.com/p/react-easy-router/issues
- npm.io page: https://npm.io/package/@rq/react-easy-router

## Dependencies (7)

- [react](https://npm.io/package/react.md) 15.x || 16.x
- [history](https://npm.io/package/history.md) ^4.7.2
- [urljoin](https://npm.io/package/urljoin.md) 0.x
- [react-dom](https://npm.io/package/react-dom.md) 15.x || 16.x
- [url-pattern](https://npm.io/package/url-pattern.md) 1.x
- [query-string](https://npm.io/package/query-string.md) ^5.0.0
- [shallowequal](https://npm.io/package/shallowequal.md) 1.x

## 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

- 3.2.2 (latest) — 2023-03-11
- 3.2.1 — 2023-03-11
- 3.2.0 — 2023-03-11
- 3.1.3 — 2019-12-25
- 3.1.2 — 2019-12-25
- 3.1.1 — 2019-12-25
- 3.0.10 — 2018-11-11

## README

# react-easy-router

A simple and lightweight alternative to `react-router`.

## Usage

```js
// Main routes file: routes.js
import user from 'modules/user/routes';
import catalog from 'modules/catalog/routes';

export default {
	...user,
	...catalog
};
```

```js
// Module route file: modules/user/routes.js

import * as Handlers from './handlers';
import { AppBase } from 'app';

export default {
    UserList: {path: '/user/list', component: Handlers.List, wrapper: AppBase},
    UserView: {path: '/user/:user_id', component: Handlers.View, wrapper: AppBase}
}
```

```js
// index file
import React from 'react';
import { render } from 'react-dom';
import { createHistory, useBasename } from 'history'
import routes from './routes';

// Redux store, optional
import store from './store';
import { Provider } from 'react-redux';

// Example for historyCallback
import * as actions from 'modules/core/actions/core';

const history = useBasename(createHistory)({
	basename: '/'
});

render((
    <Provider store={store}>
        <Router
            historyCallback={() => {
            	// do something when route changed
            	// Example:
            	store.dispatch(actions.didChangeRoute())
            }}
            history={history}
            notFound={notFound} // optional 404 handler, can be null
            routes={routes}/>
    </Provider>
), document.getElementById('app'));
```

Build url:
```js
import { Link } from 'react-easy-router';

...

<Link to="UserView" params={{user_id: 1}} className="user-link" {...props}>Text</Link>
```

Specify [url-pattern](https://github.com/snd/url-pattern) options for URL
matching:

```js


// Module route file: modules/user/routes.js

import * as Handlers from './handlers';
import { AppBase } from 'app';

export default {
    // Recognizes /user/ada.lovelace
    UserView: {path: '/user/:name', options: {segmentValueCharset: '.a-z'},
        component: Handlers.View, wrapper: AppBase},
}
```

## Changelog

### 3.2

- Replaced `componentWillMount` usage with constructor and
`componentWillReceiveProps` with `componentDidUpdate` for React 17 compatibility.

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