Skip to content

Commit d93a5e8

Browse files
committed
fix guards on initial load and guard redirect
1 parent 380b18d commit d93a5e8

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

src/history/abstract.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export class AbstractHistory extends History {
1414
}
1515

1616
push (location: RawLocation) {
17-
super.push(location, route => {
17+
super.transitionTo(location, route => {
1818
this.stack = this.stack.slice(0, this.index + 1).concat(route)
1919
this.index++
2020
})
2121
}
2222

2323
replace (location: RawLocation) {
24-
super.replace(location, route => {
24+
super.transitionTo(location, route => {
2525
this.stack = this.stack.slice(0, this.index).concat(route)
2626
})
2727
}

src/history/base.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ export class History {
1414
afterHooks: Array<?Function>;
1515
cb: Function;
1616

17+
// implemented by sub-classes
18+
go: Function;
19+
push: Function;
20+
replace: Function;
21+
1722
constructor (router: VueRouter, base: ?string) {
1823
this.router = router
1924
this.base = normalizeBae(base)
20-
this.current = router.match(this.getLocation())
25+
this.current = router.match('/')
2126
this.pending = null
2227
this.beforeHooks = []
2328
this.afterHooks = []
29+
this.transitionTo(this.getLocation())
2430
}
2531

2632
listen (cb: Function) {
@@ -35,23 +41,15 @@ export class History {
3541
this.afterHooks.push(fn)
3642
}
3743

38-
push (location: RawLocation, cb?: Function) {
39-
this.transitionTo(location, cb)
40-
}
41-
42-
replace (location: RawLocation, cb?: Function) {
43-
this.transitionTo(location, cb, true)
44-
}
45-
46-
transitionTo (location: RawLocation, cb?: Function, replace?: boolean) {
44+
transitionTo (location: RawLocation, cb?: Function) {
4745
const route = this.router.match(location, this.current)
4846
this.confirmTransition(route, () => {
4947
this.updateRoute(route)
5048
cb && cb(route)
51-
}, replace)
49+
})
5250
}
5351

54-
confirmTransition (route: Route, cb: Function, replace?: boolean) {
52+
confirmTransition (route: Route, cb: Function) {
5553
if (isSameRoute(route, this.current)) {
5654
return
5755
}
@@ -71,9 +69,7 @@ export class History {
7169
).filter(_ => _)
7270

7371
this.pending = route
74-
const redirect = replace
75-
? location => this.replace(location)
76-
: location => this.push(location)
72+
const redirect = location => this.push(location)
7773

7874
runQueue(
7975
queue,

src/history/hash.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ export class HashHistory extends History {
4242
}
4343

4444
push (location: RawLocation) {
45-
super.push(location, route => {
45+
super.transitionTo(location, route => {
4646
pushHash(route.fullPath)
4747
})
4848
}
4949

5050
replace (location: RawLocation) {
51-
super.replace(location, route => {
51+
super.transitionTo(location, route => {
5252
replaceHash(route.fullPath)
5353
})
5454
}

src/history/html5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export class HTML5History extends History {
4141

4242
push (location: RawLocation) {
4343
const current = this.current
44-
super.push(location, route => {
44+
super.transitionTo(location, route => {
4545
pushState(cleanPath(this.base + route.fullPath))
4646
this.handleScroll(route, current, false)
4747
})
4848
}
4949

5050
replace (location: RawLocation) {
5151
const current = this.current
52-
super.replace(location, route => {
52+
super.transitionTo(location, route => {
5353
replaceState(cleanPath(this.base + route.fullPath))
5454
this.handleScroll(route, current, false)
5555
})

0 commit comments

Comments
 (0)