From 761fe010a4001b05c5d2f7873d82fdfa6eea5520 Mon Sep 17 00:00:00 2001 From: crossjs Date: Fri, 11 Nov 2016 00:17:14 +0800 Subject: [PATCH 1/2] use push instead of replace in ensureURL --- src/history/hash.js | 2 +- src/history/html5.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/history/hash.js b/src/history/hash.js index c13466477..223325a57 100644 --- a/src/history/hash.js +++ b/src/history/hash.js @@ -59,7 +59,7 @@ export class HashHistory extends History { ensureURL () { if (getHash() !== this.current.fullPath) { - replaceHash(this.current.fullPath) + pushHash(this.current.fullPath) } } } diff --git a/src/history/html5.js b/src/history/html5.js index f7b9fbba7..dfe46814b 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -61,7 +61,7 @@ export class HTML5History extends History { ensureURL () { if (getLocation(this.base) !== this.current.fullPath) { - replaceState(cleanPath(this.base + this.current.fullPath)) + pushState(cleanPath(this.base + this.current.fullPath)) } } From 94b1ac032febe0fff7e7ae8fed5d7795661b1848 Mon Sep 17 00:00:00 2001 From: crossjs Date: Mon, 14 Nov 2016 13:31:43 +0800 Subject: [PATCH 2/2] add parameter push to ensureURL, for next(false) --- src/history/base.js | 4 ++-- src/history/hash.js | 7 ++++--- src/history/html5.js | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/history/base.js b/src/history/base.js index 40cccfe6a..95d42cce2 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -17,7 +17,7 @@ export class History { go: (n: number) => void; push: (loc: RawLocation) => void; replace: (loc: RawLocation) => void; - ensureURL: () => void; + ensureURL: (push?: boolean) => void; constructor (router: VueRouter, base: ?string) { this.router = router @@ -69,7 +69,7 @@ export class History { hook(route, current, (to: any) => { if (to === false) { // next(false) -> abort navigation, ensure current URL - this.ensureURL() + this.ensureURL(true) } else if (typeof to === 'string' || typeof to === 'object') { // next('/') or next({ path: '/' }) -> redirect this.push(to) diff --git a/src/history/hash.js b/src/history/hash.js index 223325a57..667e0129d 100644 --- a/src/history/hash.js +++ b/src/history/hash.js @@ -57,9 +57,10 @@ export class HashHistory extends History { window.history.go(n) } - ensureURL () { - if (getHash() !== this.current.fullPath) { - pushHash(this.current.fullPath) + ensureURL (push?: boolean) { + const current = this.current.fullPath + if (getHash() !== current) { + push ? pushHash(current) : replaceHash(current) } } } diff --git a/src/history/html5.js b/src/history/html5.js index dfe46814b..4b28b0503 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -59,9 +59,10 @@ export class HTML5History extends History { }) } - ensureURL () { + ensureURL (push?: boolean) { if (getLocation(this.base) !== this.current.fullPath) { - pushState(cleanPath(this.base + this.current.fullPath)) + const current = cleanPath(this.base + this.current.fullPath) + push ? pushState(current) : replaceState(current) } }