Skip to content

Commit 4bb9331

Browse files
author
wanyaxing
committed
add the replace attribute in location for hooking in beforeEach
vuejs#1090
1 parent 09b772e commit 4bb9331

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/history/hash.js

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ export class HashHistory extends History {
5555

5656
replace (location: RawLocation, onComplete?: Function, onAbort?: Function) {
5757
const { current: fromRoute } = this
58+
if (typeof location === 'string'){
59+
location = {path:location}
60+
}
61+
if (typeof location === 'object' && !location.replace){
62+
location.replace = 1
63+
}
5864
this.transitionTo(location, route => {
5965
replaceHash(route.fullPath)
6066
handleScroll(this.router, route, fromRoute, false)

src/history/html5.js

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export class HTML5History extends History {
5252

5353
replace (location: RawLocation, onComplete?: Function, onAbort?: Function) {
5454
const { current: fromRoute } = this
55+
if (typeof location === 'string'){
56+
location = {path:location}
57+
}
58+
if (typeof location === 'object' && !location.replace){
59+
location.replace = 1
60+
}
5561
this.transitionTo(location, route => {
5662
replaceState(cleanPath(this.base + route.fullPath))
5763
handleScroll(this.router, route, fromRoute, false)

src/util/route.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function createRoute (
2323
meta: (record && record.meta) || {},
2424
path: location.path || '/',
2525
hash: location.hash || '',
26+
replace: location.replace || 0,
2627
query,
2728
params: location.params || {},
2829
fullPath: getFullPath(location, stringifyQuery),

0 commit comments

Comments
 (0)