From 6cacc2e17a4b3d9e938c3c36f665c533fcf97f37 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Mon, 6 Mar 2017 18:24:59 +0530 Subject: [PATCH] Add beforeHistoryChange router event. --- lib/router/index.js | 2 +- lib/router/router.js | 1 + readme.md | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/router/index.js b/lib/router/index.js index 550ef110d3e2..476d0f15d401 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -15,7 +15,7 @@ const SingletonRouter = { // Create public properties and methods of the router in the SingletonRouter const propertyFields = ['components', 'pathname', 'route', 'query'] const coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch'] -const routerEvents = ['routeChangeStart', 'routeChangeComplete', 'routeChangeError'] +const routerEvents = ['routeChangeStart', 'beforeHistoryChange', 'routeChangeComplete', 'routeChangeError'] propertyFields.forEach((field) => { // Here we need to use Object.defineProperty because, we need to return diff --git a/lib/router/router.js b/lib/router/router.js index 518d1faff774..20829092a4c6 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -157,6 +157,7 @@ export default class Router extends EventEmitter { return false } + this.emit('beforeHistoryChange', as) this.changeState(method, url, as) const hash = window.location.hash.substring(1) diff --git a/readme.md b/readme.md index 4d4037bc43b6..ff05ed3babab 100644 --- a/readme.md +++ b/readme.md @@ -310,6 +310,7 @@ Here's a list of supported events: - `routeChangeStart(url)` - Fires when a route starts to change - `routeChangeComplete(url)` - Fires when a route changed completely - `routeChangeError(err, url)` - Fires when there's an error when changing routes +- `beforeHistoryChange(url)` - Fires just before changing the browser's history - `appUpdated(nextRoute)` - Fires when switching pages and there's a new version of the app > Here `url` is the URL shown in the browser. If you call `Router.push(url, as)` (or similar), then the value of `url` will be `as`.