Skip to content

Commit 94b1ac0

Browse files
author
crossjs
committed
add parameter push to ensureURL, for next(false)
1 parent 761fe01 commit 94b1ac0

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
@@ -17,7 +17,7 @@ export class History {
1717
go: (n: number) => void;
1818
push: (loc: RawLocation) => void;
1919
replace: (loc: RawLocation) => void;
20-
ensureURL: () => void;
20+
ensureURL: (push?: boolean) => void;
2121

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

src/history/hash.js

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

60-
ensureURL () {
61-
if (getHash() !== this.current.fullPath) {
62-
pushHash(this.current.fullPath)
60+
ensureURL (push?: boolean) {
61+
const current = this.current.fullPath
62+
if (getHash() !== current) {
63+
push ? pushHash(current) : replaceHash(current)
6364
}
6465
}
6566
}

src/history/html5.js

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

62-
ensureURL () {
62+
ensureURL (push?: boolean) {
6363
if (getLocation(this.base) !== this.current.fullPath) {
64-
pushState(cleanPath(this.base + this.current.fullPath))
64+
const current = cleanPath(this.base + this.current.fullPath)
65+
push ? pushState(current) : replaceState(current)
6566
}
6667
}
6768

0 commit comments

Comments
 (0)