Skip to content

Commit a6379dd

Browse files
chore(test): added coverage for out-in transition before router enter cb
1 parent 170c449 commit a6379dd

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

Diff for: examples/navigation-guards/app.js

+34-13
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,25 @@ const Quux = {
9191
}
9292

9393
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>`,
94+
template: `
95+
<div id="nested-parent">
96+
Nested Parent
97+
<hr>
98+
<router-link to="/parent/child/1">/parent/child/1</router-link>
99+
<router-link to="/parent/child/2">/parent/child/2</router-link>
100+
<hr>
101+
<p id="bre-order">
102+
<span v-for="log in logs">{{ log }} </span>
103+
</p>
104+
<!-- #705 -->
105+
<!-- Some transitions, specifically out-in transitions, cause the view -->
106+
<!-- that is transitioning in to appear significantly later than normal, -->
107+
<!-- which can cause bugs as "vm" below in "next(vm => ...)" may not be -->
108+
<!-- available at the time the callback is called -->
109+
<transition name="fade" mode="out-in">
110+
<router-view/>
111+
</transition>
112+
</div>`,
103113
data: () => ({ logs: [] }),
104114
beforeRouteEnter (to, from, next) {
105115
next(vm => {
@@ -116,7 +126,18 @@ const GuardMixin = {
116126
}
117127
}
118128

119-
const NestedChild = {
129+
const NestedChild1 = {
130+
props: ['n'],
131+
template: `<div>Child {{ n }}</div>`,
132+
mixins: [GuardMixin],
133+
beforeRouteEnter (to, from, next) {
134+
next(vm => {
135+
vm.$parent.logs.push('child ' + vm.n)
136+
})
137+
}
138+
}
139+
140+
const NestedChild2 = {
120141
props: ['n'],
121142
template: `<div>Child {{ n }}</div>`,
122143
mixins: [GuardMixin],
@@ -162,10 +183,10 @@ const router = new VueRouter({
162183
path: '/parent',
163184
component: NestedParent,
164185
children: [
165-
{ path: 'child/1', component: NestedChild, props: { n: 1 }},
166-
{ path: 'child/2', component: NestedChild, props: { n: 2 }}
186+
{ path: 'child/1', component: NestedChild1, props: { n: 1 }},
187+
{ path: 'child/2', component: NestedChild2, props: { n: 2 }}
167188
]
168-
}
189+
},
169190
]
170191
})
171192

Diff for: examples/navigation-guards/index.html

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<!DOCTYPE html>
22
<link rel="stylesheet" href="/global.css">
3+
<style>
4+
.fade-enter-active, .fade-leave-active {
5+
transition: opacity .5s ease;
6+
}
7+
.fade-enter, .fade-leave-active {
8+
opacity: 0;
9+
}
10+
</style>
311
<a href="/">&larr; Examples index</a>
412
<div id="app"></div>
513
<script src="/__build__/shared.chunk.js"></script>

0 commit comments

Comments
 (0)