@@ -38,7 +38,10 @@ const Baz = {
38
38
</div>
39
39
` ,
40
40
beforeRouteLeave ( to , from , next ) {
41
- if ( this . saved || window . confirm ( 'Not saved, are you sure you want to navigate away?' ) ) {
41
+ if (
42
+ this . saved ||
43
+ window . confirm ( 'Not saved, are you sure you want to navigate away?' )
44
+ ) {
42
45
next ( )
43
46
} else {
44
47
next ( false )
@@ -87,6 +90,43 @@ const Quux = {
87
90
}
88
91
}
89
92
93
+ const NestedParent = {
94
+ template : `<div id="nested-parent">Nested Parent <hr>
95
+ <router-link to="/parent/child/1">/parent/child/1</router-link>
96
+ <router-link to="/parent/child/2">/parent/child/2</router-link>
97
+ <hr>
98
+ <p id="bre-order">
99
+ <span v-for="log in logs">{{ log }} </span>
100
+ </p>
101
+
102
+ <router-view/></div>` ,
103
+ data : ( ) => ( { logs : [ ] } ) ,
104
+ beforeRouteEnter ( to , from , next ) {
105
+ next ( vm => {
106
+ vm . logs . push ( 'parent' )
107
+ } )
108
+ }
109
+ }
110
+
111
+ const GuardMixin = {
112
+ beforeRouteEnter ( to , from , next ) {
113
+ next ( vm => {
114
+ vm . $parent . logs . push ( 'mixin' )
115
+ } )
116
+ }
117
+ }
118
+
119
+ const NestedChild = {
120
+ props : [ 'n' ] ,
121
+ template : `<div>Child {{ n }}</div>` ,
122
+ mixins : [ GuardMixin ] ,
123
+ beforeRouteEnter ( to , from , next ) {
124
+ next ( vm => {
125
+ vm . $parent . logs . push ( 'child ' + vm . n )
126
+ } )
127
+ }
128
+ }
129
+
90
130
const router = new VueRouter ( {
91
131
mode : 'history' ,
92
132
base : __dirname ,
@@ -107,14 +147,25 @@ const router = new VueRouter({
107
147
{ path : '/qux' , component : Qux } ,
108
148
109
149
// in-component beforeRouteEnter hook for async components
110
- { path : '/qux-async' , component : resolve => {
111
- setTimeout ( ( ) => {
112
- resolve ( Qux )
113
- } , 0 )
114
- } } ,
150
+ {
151
+ path : '/qux-async' ,
152
+ component : resolve => {
153
+ setTimeout ( ( ) => {
154
+ resolve ( Qux )
155
+ } , 0 )
156
+ }
157
+ } ,
115
158
116
159
// in-component beforeRouteUpdate hook
117
- { path : '/quux/:id' , component : Quux }
160
+ { path : '/quux/:id' , component : Quux } ,
161
+ {
162
+ path : '/parent' ,
163
+ component : NestedParent ,
164
+ children : [
165
+ { path : 'child/1' , component : NestedChild , props : { n : 1 } } ,
166
+ { path : 'child/2' , component : NestedChild , props : { n : 2 } }
167
+ ]
168
+ }
118
169
]
119
170
} )
120
171
@@ -140,6 +191,7 @@ new Vue({
140
191
<li><router-link to="/qux-async">/qux-async</router-link></li>
141
192
<li><router-link to="/quux/1">/quux/1</router-link></li>
142
193
<li><router-link to="/quux/2">/quux/2</router-link></li>
194
+ <li><router-link to="/parent/child/2">/parent/child/2</router-link></li>
143
195
</ul>
144
196
<router-view class="view"></router-view>
145
197
</div>
0 commit comments