File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11import { mockWarn } from 'jest-mock-warn'
22import { createMemoryHistory , createRouter } from '../src'
3- import { defineComponent , FunctionalComponent , h } from 'vue'
3+ import {
4+ defineAsyncComponent ,
5+ defineComponent ,
6+ FunctionalComponent ,
7+ h ,
8+ } from 'vue'
49
510let component = defineComponent ( { } )
611
@@ -177,6 +182,23 @@ describe('warnings', () => {
177182 expect ( '"/foo" is a Promise instead of a function' ) . toHaveBeenWarned ( )
178183 } )
179184
185+ it ( 'warns if use defineAsyncComponent in routes' , async ( ) => {
186+ const router = createRouter ( {
187+ history : createMemoryHistory ( ) ,
188+ // simulates import('./component.vue')
189+ routes : [
190+ {
191+ path : '/foo' ,
192+ component : defineAsyncComponent ( ( ) => Promise . resolve ( { } ) ) ,
193+ } ,
194+ ] ,
195+ } )
196+ await router . push ( '/foo' )
197+ expect (
198+ `Component "default" in record with path "/foo" is defined using "defineAsyncComponent()". Write "() => import('./MyPage.vue')" instead of "defineAsyncComponent(() => import('./MyPage.vue'))"`
199+ ) . toHaveBeenWarned ( )
200+ } )
201+
180202 it ( 'warns if no route matched' , async ( ) => {
181203 const router = createRouter ( {
182204 history : createMemoryHistory ( ) ,
Original file line number Diff line number Diff line change @@ -261,6 +261,16 @@ export function extractComponentsGuards(
261261 )
262262 let promise = rawComponent
263263 rawComponent = ( ) => promise
264+ } else if (
265+ ( rawComponent as any ) . __asyncLoader &&
266+ guardType === 'beforeRouteEnter'
267+ ) {
268+ warn (
269+ `Component "${ name } " in record with path "${ record . path } " is defined ` +
270+ `using "defineAsyncComponent()". ` +
271+ `Write "() => import('./MyPage.vue')" instead of ` +
272+ `"defineAsyncComponent(() => import('./MyPage.vue'))".`
273+ )
264274 }
265275 }
266276
You can’t perform that action at this time.
0 commit comments