# location-init

> Simple route callbacks

Latest version **0.1.3** (published 2022-06-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install location-init
pnpm add location-init
yarn add location-init
bun add location-init
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2022-06-14 |
| First published | 2014-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Tobias Bleckert |
| Maintainers | tbleckert |
| Keywords | router, js, simple, callback, init, small |

## Links

- npm: https://www.npmjs.com/package/location-init
- Repository: https://github.com/tbleckert/location-init
- Issues: https://github.com/tbleckert/location-init/issues
- npm.io page: https://npm.io/package/location-init

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.3 (latest) — 2022-06-14
- 0.0.1 (beta) — 2014-11-23
- 0.1.2 — 2022-06-11
- 0.1.1 — 2022-06-11
- 0.1.0 — 2022-06-11
- 0.0.4 — 2015-06-27
- 0.0.3 — 2015-06-27
- 0.0.2 — 2015-03-08

## README

Location Init
=============
_<0.5kb minified and gzipped_

Sometimes you just want to trigger something on a certain page, location-init is perfect for that. Think of it as a callback to normal page requests. No magic, just simple route callbacks that triggers on page requests. Of course you can also trigger the route dispatcher manually whenever you want, for example on popstate, but it's not handled automatically.

## Install

Download dist/build.min.js or install with npm (`npm install location-init`).

## Usage

Simply create a new router like this:

    const router = new Router();

You can also create the router with a base url (will be prepended on all routes) and/or a routes object.

    const router = new Router('/user', {
    	profile(route, path) {

    	},
    	settings(route, path) {

    	}
    });

You can also add routes after init and call `dispatch` manually. This is how you add routes:

    router.on('/profile', (route, path, event) => {

    });

    router.on('/splat/*', (route, path, event) => {

    });

    router.on('/named/:id', (route, path, event) => {

    });

    router.dispatch();

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