# mfrouter

> Cross Platform JS router

Latest version **1.3.2** (published 2017-12-18) · ISC license · 0 weekly downloads

## Install

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

## 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.3.2 |
| Published | 2017-12-18 |
| First published | 2017-12-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mcfinley |
| Maintainers | mcfinley |

## Links

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

## Dependencies (2)

- [mfreactivity](https://npm.io/package/mfreactivity.md) ^1.1.0
- [universal-url](https://npm.io/package/universal-url.md) ^1.0.0

## Recent versions

- 1.3.2 (latest) — 2017-12-18
- 1.2.2 — 2017-12-18
- 1.2.1 — 2017-12-18
- 1.1.1 — 2017-12-15
- 1.2.0 — 2017-12-15
- 1.1.0 — 2017-12-15
- 1.0.0 — 2017-12-15

## README

## mfrouter

Exports history-like object for every platform.

### History API

#### `length: number`

Property that returns the count of entries. Will be `1` when page is loaded.

#### `back(): void`

Gets one page back

#### `forward(): void`

Gets one page forward if possible

#### `go(steps: number): void`

Goes `steps` back or forward

#### `pushState(state: any, url: string, title: string): void`

Create a new entry in history

#### `replaceState(state: any, url: string, title: string): void`

Replaces the last entry in the history

#### `subscribe(listener: Function): Function`

*Custom* is part of `mfrouter` only. Binds a listener to history changes (from inside code as well as from outside). Returns a function that removes that listener

### History Location mixin API

```
http://test.com/page?query=2#some-hash
  |      |        |     |      |
  |      |        |     |      +--hash
  |      |        |     +--search
  |      |        +--pathname
  |      +--host
  +--protocol
```

#### `href(): string`

Returns current page full path (`http://test.com/page?query=2#some-hash`)

#### `protocol(): string`

Return protocol (`http:`)

#### `host(): string`

Returns host (`test.com`)

#### `pathname(): string`

Returns pathname (`/page`)

#### `search(): string`

Returns query string (`?query=2`)

#### `hash(): string`

Returns hash part of url (`#some-hash`)

### Example

#### Cordova

```
  const fakeHistoryFactory = require('mfrouter/fake');
  const history = fakeHistoryFactory();

  // Will go back with history when backbutton is pressed
  // If no history entries will leave
  document.addEventListener('deviceready', function () {
    document.addEventListener('backbutton', function (e) {
      e.preventDefault();
      e.stopPropagation();

      if (history.length > 1)
        history.back();
      else
        navigator.app.exitApp();
    });
  }, false);

  history.subscribe(function () {
    alert('Navigated, current url:' + history.href());
  });
```

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