Skip to content

Commit e4b3fbe

Browse files
committedJul 2, 2020
fix(warn): warn when RouterView is wrapped with transition
1 parent 994c073 commit e4b3fbe

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed
 

‎__tests__/RouterView.spec.ts

+83
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,89 @@ describe('RouterView', () => {
293293
expect(wrapper.html()).toBe(`<div>id:2;other:page</div>`)
294294
})
295295

296+
describe('warnings', () => {
297+
it('does not warn RouterView is wrapped', async () => {
298+
const route = createMockedRoute(routes.root)
299+
const wrapper = await mount(
300+
{
301+
template: `
302+
<div>
303+
<router-view/>
304+
</div>
305+
`,
306+
},
307+
{
308+
propsData: {},
309+
provide: route.provides,
310+
components: { RouterView },
311+
}
312+
)
313+
expect(wrapper.html()).toBe(`<div><div>Home</div></div>`)
314+
expect('can no longer be used directly inside').not.toHaveBeenWarned()
315+
})
316+
it('warns if KeepAlive wraps a RouterView', async () => {
317+
const route = createMockedRoute(routes.root)
318+
const wrapper = await mount(
319+
{
320+
template: `
321+
<keep-alive>
322+
<router-view/>
323+
</keep-alive>
324+
`,
325+
},
326+
{
327+
propsData: {},
328+
provide: route.provides,
329+
components: { RouterView },
330+
}
331+
)
332+
expect(wrapper.html()).toBe(`<div>Home</div>`)
333+
expect('can no longer be used directly inside').toHaveBeenWarned()
334+
})
335+
336+
it('warns if KeepAlive and Transition wrap a RouterView', async () => {
337+
const route = createMockedRoute(routes.root)
338+
const wrapper = await mount(
339+
{
340+
template: `
341+
<transition>
342+
<keep-alive>
343+
<router-view/>
344+
</keep-alive>
345+
</transition>
346+
`,
347+
},
348+
{
349+
propsData: {},
350+
provide: route.provides,
351+
components: { RouterView },
352+
}
353+
)
354+
expect(wrapper.html()).toBe(`<div>Home</div>`)
355+
expect('can no longer be used directly inside').toHaveBeenWarned()
356+
})
357+
358+
it('warns if Transition wraps a RouterView', async () => {
359+
const route = createMockedRoute(routes.root)
360+
const wrapper = await mount(
361+
{
362+
template: `
363+
<transition>
364+
<router-view/>
365+
</transition>
366+
`,
367+
},
368+
{
369+
propsData: {},
370+
provide: route.provides,
371+
components: { RouterView },
372+
}
373+
)
374+
expect(wrapper.html()).toBe(`<div>Home</div>`)
375+
expect('can no longer be used directly inside').toHaveBeenWarned()
376+
})
377+
})
378+
296379
describe('KeepAlive', () => {
297380
async function factory(
298381
initialRoute: RouteLocationNormalizedLoose,

‎src/RouterView.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ export const RouterView = (RouterViewImpl as any) as {
115115
function warnDeprecatedUsage() {
116116
const instance = getCurrentInstance()!
117117
const parentName = instance.parent && instance.parent.type.name
118-
if (parentName === 'KeepAlive' || parentName === 'Transition') {
118+
if (
119+
parentName &&
120+
(parentName === 'KeepAlive' || parentName.includes('Transition'))
121+
) {
119122
const comp = parentName === 'KeepAlive' ? 'keep-alive' : 'transition'
120123
warn(
121124
`<router-view> can no longer be used directly inside <transition> or <keep-alive>.\n` +

0 commit comments

Comments
 (0)