1. 在初始化路由对象时,使用这种静态写死的方式
component: () => import('@/views/form/index'),
没有问题。
2. 使用动态传参的方式
后台传一个对象obj,然后用这种方式
component: () => import(obj.url),
有问题!
报错,说找不到'@/views/form/index' ,尽管看起来和方法1没有区别。
解决方式:
1. 引入动态参数插件
npm install --save-dev babel-plugin-syntax-dynamic-import
2. 然后使用`...${}...`的方式
component: () => import(`@/views/${obj.url}`),
搞定!路由活了起来~~~