mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Add beforeHistoryChange router event. (#1360)
This commit is contained in:
parent
f9286f74bf
commit
6db7101c40
|
@ -15,7 +15,7 @@ const SingletonRouter = {
|
||||||
// Create public properties and methods of the router in the SingletonRouter
|
// Create public properties and methods of the router in the SingletonRouter
|
||||||
const propertyFields = ['components', 'pathname', 'route', 'query']
|
const propertyFields = ['components', 'pathname', 'route', 'query']
|
||||||
const coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch']
|
const coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch']
|
||||||
const routerEvents = ['routeChangeStart', 'routeChangeComplete', 'routeChangeError']
|
const routerEvents = ['routeChangeStart', 'beforeHistoryChange', 'routeChangeComplete', 'routeChangeError']
|
||||||
|
|
||||||
propertyFields.forEach((field) => {
|
propertyFields.forEach((field) => {
|
||||||
// Here we need to use Object.defineProperty because, we need to return
|
// Here we need to use Object.defineProperty because, we need to return
|
||||||
|
|
|
@ -168,6 +168,7 @@ export default class Router extends EventEmitter {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.emit('beforeHistoryChange', as)
|
||||||
this.changeState(method, url, as, options)
|
this.changeState(method, url, as, options)
|
||||||
const hash = window.location.hash.substring(1)
|
const hash = window.location.hash.substring(1)
|
||||||
|
|
||||||
|
|
|
@ -311,6 +311,7 @@ Here's a list of supported events:
|
||||||
- `routeChangeStart(url)` - Fires when a route starts to change
|
- `routeChangeStart(url)` - Fires when a route starts to change
|
||||||
- `routeChangeComplete(url)` - Fires when a route changed completely
|
- `routeChangeComplete(url)` - Fires when a route changed completely
|
||||||
- `routeChangeError(err, url)` - Fires when there's an error when changing routes
|
- `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
|
- `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`.
|
> 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`.
|
||||||
|
|
Loading…
Reference in a new issue