Skip to content

Commit 3cbc0f3

Browse files
Jinjiangyyx990803
authored andcommitted
fix: avoid first popstate event with async guard together (fix #1508) (#1661)
1 parent a06e0b2 commit 3cbc0f3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/history/html5.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import type Router from '../index'
44
import { History } from './base'
55
import { cleanPath } from '../util/path'
6+
import { START } from '../util/route'
67
import { setupScroll, handleScroll } from '../util/scroll'
78
import { pushState, replaceState } from '../util/push-state'
89

@@ -16,9 +17,18 @@ export class HTML5History extends History {
1617
setupScroll()
1718
}
1819

20+
const initLocation = getLocation(this.base)
1921
window.addEventListener('popstate', e => {
2022
const current = this.current
21-
this.transitionTo(getLocation(this.base), route => {
23+
24+
// Avoiding first `popstate` event dispatched in some browsers but first
25+
// history route not updated since async guard at the same time.
26+
const location = getLocation(this.base)
27+
if (this.current === START && location === initLocation) {
28+
return
29+
}
30+
31+
this.transitionTo(location, route => {
2232
if (expectScroll) {
2333
handleScroll(router, route, current, true)
2434
}

0 commit comments

Comments
 (0)