# teardrop

> Declarative routing for React

Latest version **5.0.4** (published 2017-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install teardrop
pnpm add teardrop
yarn add teardrop
bun add teardrop
```

## 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 | 5.0.4 |
| Published | 2017-09-21 |
| First published | 2017-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | willhackett |
| Keywords | react, router, route, routing, history, link |

## Links

- npm: https://www.npmjs.com/package/teardrop
- Repository: https://github.com/OpenClubDev/teardrop
- Homepage: https://github.com/OpenClubDev/teardrop#readme
- Issues: https://github.com/OpenClubDev/teardrop/issues
- npm.io page: https://npm.io/package/teardrop

## Dependencies (4)

- [history](https://npm.io/package/history.md) ^4.3.0
- [query-string](https://npm.io/package/query-string.md) 4.2.3
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^1.5.3
- [react-broadcast](https://npm.io/package/react-broadcast.md) ^0.5.2

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

- 5.0.4 (latest) — 2017-09-21
- 5.0.3 — 2017-04-25
- 5.0.2 — 2017-03-20
- 5.0.1 — 2017-03-20
- 5.0.0 — 2017-03-14

## README

# Teardrop [![Travis][build-badge]][build]

[build-badge]: https://img.shields.io/travis/OpenClubDev/teardrop/master.svg?style=flat-square
[build]: https://travis-ci.org/OpenClubDev/teardrop

<img src="https://github.com/OpenClubDev/teardrop/raw/master/logo/teardrop.png" height="150"/>

Declarative routing for [React](https://facebook.github.io/react).

React Router keeps your UI in sync with the URL. Make the URL your first thought, not an after-thought.

## Installation

Using [npm](https://www.npmjs.com/):

    $ npm install --save teardrop@5.0.0

Then with a module bundler like [webpack](https://webpack.github.io/), use as you would anything else:

```js
// using an ES6 transpiler, like babel
import { BrowserRouter, Match, Link, Miss } from 'teardrop'

// not using an ES6 transpiler
var BrowserRouter = require('teardrop').BrowserRouter
var Match = require('teardrop').Match
var Link = require('teardrop').Link
var Miss = require('teardrop').Miss
```

You can find the library on `window.Teardrop`.

## Docs

We're going to try and get the docs sorted out here.

## v5 FAQ

### Why rename and fork teardrop?

We weren't happy with the direction of teardrop, so we've decided to branch out and provide our own version.

### Will you do huge API overhauls?

No, we're not about that. We'll try and ensure everything is backwards compatible for as long as possible.

### Why Match, Miss instead of Route?

We like it.

### What about route transition hooks?

Transition's can be done within render of a Match.

```js
<Match render={() => {
  doStuffHere();
  return <ComponentHere />
}}/>
```

One use case was loading data and waiting to render the next screen until the data landed. With a component, you can save the previous children, render them while loading, and then render your new children when you're done. We'll have an example of this eventually.

### I liked seeing all my routes in one place, now what?

Check out the "Route Config" example.
`website/examples/RouterConfig.js`

### Example

Right now, because we're lacking pretty documentation, you'll have to use this example and the modules/__tests__ folder to figure out what's going on. Doccos are in progress. :)

#### Server Router example
```javascript:
import { ServerRouter, MatchGroup, Match, Miss, Redirect, createServerRenderContext } from 'teardrop';

const location = '/test' // Set this using your server
const routerContext = createServerRenderContext();

render() {
  return (
    <ServerRouter location={URL from server} context={routerContext}>
    {/* This component will return every time the pattern is matched - anywhere in the app */}
      <Match
        exact={true|false}
        pattern="*"
        render={({ params, location, pathname, isExact}) => {
          // params is an object containing params from your pattern
          // location is the current location object
          // pathname is the current pathname
          // isExact is true when the pattern is an "exact" match (ie. "/" === "/")
          // pattern is also returned in case you want it
          return <div />
        }}
      />
      <MatchGroup>
        // Put as many matches in here as you want, it'll only match ONE of them
        <Match pattern="hi" render={Hi} />
        <Match pattern="hello" render={Hello} />
        <Match pattern="hey" render={Hey} />
      </MatchGroup>
      { /* Simple redirect component */ }
      <Match pattern="/old-link" render={() => {
        <Redirect to="/new-link" />
        }} />
      { /* Nothing matched? We produce a Miss */ }
      <Miss render={ErrorPage} />
    </ServerRouter>
    );
}

```

#### Client Router example

```javascript:
import { BrowserRouter, MatchGroup, Match, Miss, Redirect, createServerRenderContext } from 'teardrop';

render() {
  return (
    <BrowserRouter>
    {/* This component will return every time the pattern is matched - anywhere in the app */}
      <Match
        exact={true|false}
        pattern="*"
        render={({ params, location, pathname, isExact}) => {
          // params is an object containing params from your pattern
          // location is the current location object
          // pathname is the current pathname
          // isExact is true when the pattern is an "exact" match (ie. "/" === "/")
          // pattern is also returned in case you want it
          return <div />
        }}
      />
      <MatchGroup>
        // Put as many matches in here as you want, it'll only match ONE of them
        <Match pattern="hi" render={Hi} />
        <Match pattern="hello" render={Hello} />
        <Match pattern="hey" render={Hey} />
      </MatchGroup>
      { /* Simple redirect component */ }
      <Match pattern="/old-link" render={() => {
        <Redirect to="/new-link" />
        }} />
      { /* Nothing matched? We produce a Miss */ }
      <Miss render={ErrorPage} />
    </BrowserRouter>
    );
}

```

### Changelog

**5.0.1**

 - Now sending `router` and `location` props to the Router's only child.

 **5.0.2**

 - Exporting `MatchGroup` for ease of use.

 **5.0.3**

 - Supporting 'prop-types' from react

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