File tree 2 files changed +45
-8
lines changed
2 files changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -94,10 +94,10 @@ export class History {
94
94
// Exception should still be thrown
95
95
throw e
96
96
}
97
+ const prev = this . current
97
98
this . confirmTransition (
98
99
route ,
99
100
( ) => {
100
- const prev = this . current
101
101
this . updateRoute ( route )
102
102
onComplete && onComplete ( route )
103
103
this . ensureURL ( )
@@ -118,17 +118,15 @@ export class History {
118
118
onAbort ( err )
119
119
}
120
120
if ( err && ! this . ready ) {
121
- this . ready = true
122
- // Initial redirection should still trigger the onReady onSuccess
121
+ // Initial redirection should not mark the history as ready yet
122
+ // because it's triggered by the redirection instead
123
123
// https://github.com/vuejs/vue-router/issues/3225
124
- if ( ! isNavigationFailure ( err , NavigationFailureType . redirected ) ) {
124
+ // https://github.com/vuejs/vue-router/issues/3331
125
+ if ( ! isNavigationFailure ( err , NavigationFailureType . redirected ) || prev !== START ) {
126
+ this . ready = true
125
127
this . readyErrorCbs . forEach ( cb => {
126
128
cb ( err )
127
129
} )
128
- } else {
129
- this . readyCbs . forEach ( cb => {
130
- cb ( route )
131
- } )
132
130
}
133
131
}
134
132
}
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue'
2
+ import VueRouter from '../../../src/index'
3
+
4
+ Vue . use ( VueRouter )
5
+
6
+ describe ( 'onReady order' , ( ) => {
7
+ function factory ( ) {
8
+ const router = new VueRouter ( {
9
+ mode : 'abstract' ,
10
+ routes : [
11
+ { path : '/' , component : { } } ,
12
+ { path : '/foo' , component : { } }
13
+ ]
14
+ } )
15
+
16
+ return { router }
17
+ }
18
+
19
+ it ( 'should trigger onReady after push with redirect' , done => {
20
+ const { router } = factory ( )
21
+
22
+ let n = 0
23
+ const count = 2
24
+ router . onReady ( ( ) => {
25
+ expect ( router . currentRoute . path ) . toBe ( '/foo' )
26
+ if ( ++ n === count ) done ( )
27
+ } )
28
+
29
+ router . beforeEach ( ( to , from , next ) => {
30
+ if ( to . path === '/' ) next ( '/foo' )
31
+ else next ( )
32
+ } )
33
+
34
+ router . push ( '/' ) . catch ( ( ) => {
35
+ expect ( router . currentRoute . path ) . toBe ( '/foo' )
36
+ if ( ++ n === count ) done ( )
37
+ } )
38
+ } )
39
+ } )
You can’t perform that action at this time.
0 commit comments