Skip to content

Commit 13e64d6

Browse files
authored
use push instead of replace in ensureURL (#894)
* use push instead of replace in ensureURL * add parameter push to ensureURL, for next(false)
2 parents 7346720 + 94b1ac0 commit 13e64d6

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/history/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class History {
1818
go: (n: number) => void;
1919
push: (loc: RawLocation) => void;
2020
replace: (loc: RawLocation) => void;
21-
ensureURL: () => void;
21+
ensureURL: (push?: boolean) => void;
2222

2323
constructor (router: VueRouter, base: ?string) {
2424
this.router = router
@@ -70,7 +70,7 @@ export class History {
7070
hook(route, current, (to: any) => {
7171
if (to === false) {
7272
// next(false) -> abort navigation, ensure current URL
73-
this.ensureURL()
73+
this.ensureURL(true)
7474
} else if (typeof to === 'string' || typeof to === 'object') {
7575
// next('/') or next({ path: '/' }) -> redirect
7676
this.push(to)

src/history/hash.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ export class HashHistory extends History {
5252
window.history.go(n)
5353
}
5454

55-
ensureURL () {
56-
if (getHash() !== this.current.fullPath) {
57-
replaceHash(this.current.fullPath)
55+
ensureURL (push?: boolean) {
56+
const current = this.current.fullPath
57+
if (getHash() !== current) {
58+
push ? pushHash(current) : replaceHash(current)
5859
}
5960
}
6061
}

src/history/html5.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ export class HTML5History extends History {
5757
})
5858
}
5959

60-
ensureURL () {
60+
ensureURL (push?: boolean) {
6161
if (getLocation(this.base) !== this.current.fullPath) {
62-
replaceState(cleanPath(this.base + this.current.fullPath))
62+
const current = cleanPath(this.base + this.current.fullPath)
63+
push ? pushState(current) : replaceState(current)
6364
}
6465
}
6566

0 commit comments

Comments
 (0)