Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaydenseric/next-router-events
A more powerful Next.js router events API.
https://github.com/jaydenseric/next-router-events
nextjs
Last synced: 17 days ago
JSON representation
A more powerful Next.js router events API.
- Host: GitHub
- URL: https://github.com/jaydenseric/next-router-events
- Owner: jaydenseric
- Created: 2017-10-18T02:21:27.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-04T22:21:51.000Z (almost 6 years ago)
- Last Synced: 2024-10-04T12:52:50.006Z (about 1 month ago)
- Topics: nextjs
- Language: JavaScript
- Homepage: https://npm.im/next-router-events
- Size: 11.7 KB
- Stars: 26
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
Awesome Lists containing this project
README
# next-router-events
[![Build status](https://travis-ci.org/jaydenseric/next-router-events.svg)](https://travis-ci.org/jaydenseric/next-router-events) [![npm version](https://img.shields.io/npm/v/next-router-events.svg)](https://npm.im/next-router-events)
A more powerful Next.js router events API. The standard API can only handle one listener per router event (see [zeit/next.js#2033](https://github.com/zeit/next.js/issues/2033)).
## Setup
To install [`next-router-events`](https://npm.im/next-router-events) from [npm](https://npmjs.com) run:
```
npm install next-router-events
```## Usage
To use router events:
```js
import routerEvents from 'next-router-events'const logUrl = url => console.log(url)
const alertUrl = url => alert(url)routerEvents.on('routeChangeComplete', logUrl)
routerEvents.once('routeChangeComplete', alertUrl)
routerEvents.off('routeChangeComplete', logUrl)
```See `next` [router events](https://github.com/zeit/next.js#router-events) and `tiny-emitter` [instance methods](https://github.com/scottcorgan/tiny-emitter#instance-methods).