# router-for-spa

> A simple router

Latest version **0.1.1** (published 2019-04-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install router-for-spa
pnpm add router-for-spa
yarn add router-for-spa
bun add router-for-spa
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2019-04-10 |
| First published | 2016-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | noski |
| Maintainers | noski |
| Keywords | router, hash, url |

## Links

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

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

- 0.1.1 (latest) — 2019-04-10
- 0.0.4 — 2016-11-16
- 0.0.3 — 2016-11-16
- 0.0.2 — 2016-11-16
- 0.0.1 — 2016-11-16

## README

## router-for-spa
![npm-image](http://img.shields.io/npm/v/router-for-spa.svg)
![downloads-image](http://img.shields.io/npm/dw/router-for-spa.svg)
![downloads-image](http://img.shields.io/npm/dm/router-for-spa.svg)
![downloads-image](http://img.shields.io/npm/dy/router-for-spa.svg)
![downloads-image](http://img.shields.io/npm/dt/router-for-spa.svg)
![travis-image](http://img.shields.io/travis/hunnble/router-for-spa.svg)
>A simple front end router. [source code](https://github.com/hunnble/router-for-spa)

#### Platform Support
This library can be used in the **browser** only.
#### Get the code
```javascript
npm install --save router-for-spa
```
#### Example(UMD, the module can be used in Node.js too)
##### example.html
```html
<!DOCTYPE html>
<html>
  <head>
    <title>example</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <div id="app"></div>
    <a href="#/">index</a>
    <a href="#/a">a</a>
    <a href="#/b">b</a>
    <script src="../index.js"></script>
    <script src="./example.js"></script>
  </body>
</html>
```
##### example.js
```javascript
var HashRouter = new Router();

function changeContent (content) {
  var app = document.querySelector('#app');
  app.innerHTML = content;
}

HashRouter.route('/', function () {
  changeContent('index');
});
HashRouter.route('/a', function () {
  changeContent('a');
}, {
  onEnter: function () {console.log('onEnter /a');},
  onLeave: function () {console.log('onLeave /a');}
});
HashRouter.route('/b', function () {
  changeContent('b');
  HashRouter.require('./a.js', function () {
    console.log('done!');
  });
});

```
#### License
MIT

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