Skip to content

Commit 6db7101

Browse files
arunodarauchg
authored andcommitted
Add beforeHistoryChange router event. (#1360)
1 parent f9286f7 commit 6db7101

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

lib/router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const SingletonRouter = {
1515
// Create public properties and methods of the router in the SingletonRouter
1616
const propertyFields = ['components', 'pathname', 'route', 'query']
1717
const coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch']
18-
const routerEvents = ['routeChangeStart', 'routeChangeComplete', 'routeChangeError']
18+
const routerEvents = ['routeChangeStart', 'beforeHistoryChange', 'routeChangeComplete', 'routeChangeError']
1919

2020
propertyFields.forEach((field) => {
2121
// Here we need to use Object.defineProperty because, we need to return

lib/router/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export default class Router extends EventEmitter {
168168
return false
169169
}
170170

171+
this.emit('beforeHistoryChange', as)
171172
this.changeState(method, url, as, options)
172173
const hash = window.location.hash.substring(1)
173174

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ Here's a list of supported events:
311311
- `routeChangeStart(url)` - Fires when a route starts to change
312312
- `routeChangeComplete(url)` - Fires when a route changed completely
313313
- `routeChangeError(err, url)` - Fires when there's an error when changing routes
314+
- `beforeHistoryChange(url)` - Fires just before changing the browser's history
314315
- `appUpdated(nextRoute)` - Fires when switching pages and there's a new version of the app
315316

316317
> 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`.

0 commit comments

Comments
 (0)