# activity-router

> application router that supports multiple activities.

Latest version **1.4.0** (published 2016-06-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install activity-router
pnpm add activity-router
yarn add activity-router
bun add activity-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 | 1.4.0 |
| Published | 2016-06-22 |
| First published | 2015-06-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kory Nunn |
| Maintainers | korynunn |

## Links

- npm: https://www.npmjs.com/package/activity-router
- Repository: https://github.com/KoryNunn/activity-router
- Homepage: https://github.com/KoryNunn/activity-router#readme
- Issues: https://github.com/KoryNunn/activity-router/issues
- npm.io page: https://npm.io/package/activity-router

## Dependencies (2)

- [debounce](https://npm.io/package/debounce.md) ^1.0.0
- [route-tree](https://npm.io/package/route-tree.md) ^2.3.2

## Recent versions

- 1.4.0 (latest) — 2016-06-22
- 1.3.3 — 2016-04-27
- 1.3.2 — 2016-04-27
- 1.3.1 — 2016-04-01
- 1.3.0 — 2016-04-01
- 1.2.1 — 2016-03-26
- 1.2.0 — 2015-11-17
- 1.1.1 — 2015-06-24
- 1.1.0 — 2015-06-24
- 1.0.0 — 2015-06-23

## README

# activity-router

application router that supports multiple activities.

## What

activity-router handles routing in your application if you want to have 'layers' or `activities`, similar to how activities work in android applications.

activities look like this:

```
{
    name: 'namedActivity',
    values: {key: value} // flat key: String(value) map.
}
```

and are displayed in the hash like this:

```
https://mySite.com/#/namedActivity#/anotherActivity/value
```

## Usage

activity-router uses [route-tree](https://github.com/KoryNunn/route-tree) under the covers.

Set up a router by passing in your routes just like route-tree:

```
var activityRouter = require('activity-router');

var router = activitiyRouter({
    routeName: {
        _url: '/routeurl/{routeValue}/{routeValue}'
    }
})

// initialise
router.init();
```

## API

### activityRouter.add(name, values)

add an activity.

### activityRouter.remove(activity)

remove an activity

### activityRouter.replace(name, values, index)

replace an activity at `index` with a new activity

### activityRouter.top(name, values)

replace the top activity with a new activity

### activityRouter.pop()

remove the top activity

### activityRouter.reset(name, values)

remove all activities except the first, and replace it with a new activity.

### activityRouter.init()

initialise activity-router from the hash in the URL.

## Events

activity will raise events when an activity is added/changed/removed

### router.on('add', function(newActivity, index){});

Emitted when a new activity is added

### router.on('update', function(newActivity, index){});

Emitted an existing activity is updated

### router.on('replace', function(newActivity, index){});

Emitted an existing activity is replaced

### router.on('remove', function(removedActivity, index){});

Emitted an existing activity is removed

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