# react-routes-dub

> Stupid-easy React routing for the browser in 200 lines of code and with a single dependency.

Latest version **1.5.1** (published 2020-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-routes-dub
pnpm add react-routes-dub
yarn add react-routes-dub
bun add react-routes-dub
```

## 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 | 1.5.1 |
| Published | 2020-04-07 |
| First published | 2018-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Chadwick Dahlquist |
| Maintainers | bugeats |
| Keywords | history-api, minimalist, path-to-regexp, react, react-context, react-context-api, react-route, react-router, react-routes, react-routing, route, router, routes, routing |

## Links

- npm: https://www.npmjs.com/package/react-routes-dub
- Repository: https://github.com/bugeats/react-routes-dub
- Homepage: https://github.com/bugeats/react-routes-dub#readme
- Issues: https://github.com/bugeats/react-routes-dub/issues
- npm.io page: https://npm.io/package/react-routes-dub

## Dependencies (1)

- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^3.0.0

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.5.1 (latest) — 2020-04-07
- 2.0.0-alpha.5 (alpha) — 2020-02-05
- 2.0.0-alpha.7 — 2020-02-25
- 2.0.0-alpha.6 — 2020-02-22
- 1.5.0 — 2019-03-20
- 1.4.0 — 2019-01-08
- 1.3.0 — 2019-01-07
- 1.2.1 — 2018-10-16
- 1.2.0 — 2018-10-16
- 1.1.0 — 2018-10-15
- 1.0.2 — 2018-10-12
- 1.0.1 — 2018-10-12
- 0.3.0 — 2018-09-20
- 0.2.0 — 2018-09-20
- 0.1.0 — 2018-08-08
- … 1 more at https://npm.io/package/react-routes-dub/versions

## README

# react-routes-dub

Stupid-easy React routing for the browser in 200 lines of code and with a single dependency.

That single dependency is important. [path-to-regexp](https://github.com/pillarjs/path-to-regexp) is used by Express to parse path strings, and now you can use it for your client-side routes.

Why you might use it:

- All configuration takes place in a single file, using plain JS.
- Uses the [React Context API](https://reactjs.org/docs/context.html) for minimum fuss.
- Routes are **named**, as they should be.

Why you might skip it:

- Browser only. Not for React Native, React VR, or anything else like that.


# Installation

    yarn add react-routes-dub

or
    
    npm install --save react-routes-dub


# Usage

Define your routes with a single file:

```javascript
// routes.js

import routesDub from 'react-routes-dub';

export const {
  DubProvider,
  Link,
  Route,
  pathFor
} = routesDub([
  {
    name: 'home',
    pattern: '/'
  },
  {
    name: 'pet',
    pattern: 'pets/:petId',
    onEnter: ({ params }) => {
      loadPetData(params.petId);
    },
    routes: [
      {
        name: 'toys',
        pattern: 'toys'
      }
    ]
  }
]);

```

Now everything you need to begin routing is immediately available.

```jsx
// app.jsx

import React, { Component } from 'react';
import { DubProvider, Link, Route } from './routes';

class App extends Component {
  render () {
    return (
      <DubProvider>
        <Link to='home'>Home</Link>
        <Link to='pet' params={ { petId: 'dog-1' } }>See Dog One</Link>
        <Link to='pet' params={ { petId: 'dog-2' } }>See Dog Two</Link>
        <Link to='pet.toys' params={ { petId: 'dog-1' } }>See Dog One's Toys</Link>
        <Route is='home'>
          <p>Welcome home.</p>
        </Route>
        <Route is='pet'>
          { ({ params }) => {
            // route parameters are available here
            return (
              <p>Pet ID here: { params.petId }</p>
            )
          } }
        </Route>
        <Route is='pet.toys'>
          <p>Pet Toys!</p>
        </Route>
      </DubProvider>
    );
  }
}
```

That's it! You're done.

**See [./test](./test) for a complete example.**

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