# stb-router

> STB SDK singleton for page navigation with history.

Latest version **1.3.0** (published 2015-10-13) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install stb-router
pnpm add stb-router
yarn add stb-router
bun add stb-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.3.0 |
| Published | 2015-10-13 |
| First published | 2015-10-13 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stanislav Kalashnik |
| Maintainers | darkpark |
| Keywords | stb, sdk, device, tv, devkit, framework, router |

## Links

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

## Dependencies (1)

- [stb-emitter](https://npm.io/package/stb-emitter.md) 1.*.*

## 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.3.0 (latest) — 2015-10-13

## README

STB SDK singleton for page navigation with history
==================================================

[![NPM version](https://img.shields.io/npm/v/stb-router.svg?style=flat-square)](https://www.npmjs.com/package/stb-router)
[![Dependencies Status](https://img.shields.io/david/stbsdk/router.svg?style=flat-square)](https://david-dm.org/stbsdk/router)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-blue.svg?style=flat-square)](https://gitter.im/DarkPark/stb)


`router` is a STB SDK page manager.
Each page is an instance of [Page](https://github.com/stbsdk/ui-page) component.
It is recommended to have the same name for page file name and JS instance.


## Installation

```bash
npm install stb-router
```


## Usage

Add the singleton to the scope:

```js
var router = require('stb-router');
```

Init with some existing pages:

```js
router.data([
    require('./pages/init'),
    require('./pages/main'),
    require('./pages/help')
]);
```

Each page has its ID. The same ID should be used in HTML.
Make some page active/visible by its ID:

```js
router.navigate('pageMain');
```

> This will hide the current page, activate the `pageMain` page and put it in the tail of the history list.
> All subscribers of the current and `pageMain` page will be notified with `show/hide` events.
> Also the router emits `navigate` event to all subscribers.

To get to the previous active page use:

```js
router.back();
```

Low-level attributes to handle router data manually: `router.current`, `router.history` and `router.ids`.

The module also has methods to parse location hash address and serialize it back:

```js
var parsedData = router.parse('#pageMain/some/additional/data'),
    stringData = router.stringify('pageMain', ['some', 'additional', 'data']);
```

Direct modification of the URL address should be avoided.
The methods `router.navigate` and `router.back` should be used instead.


## Debug mode

> There is a global var `DEBUG` which activates additional consistency checks and protection logic not available in release mode.

In debug mode the constructor is exposed to the global namespace as `window.router`.


## Contribution

If you have any problem or suggestion please open an issue [here](https://github.com/stbsdk/router/issues).
Pull requests are welcomed with respect to the [JavaScript Code Style](https://github.com/DarkPark/jscs).


## License

`stb-router` is released under the [GPL-3.0 License](http://opensource.org/licenses/GPL-3.0).

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