動(dòng)態(tài)路由里蟋座,將component字符串改變?yōu)槁酚蓱屑虞d方法
export default {
LogisticsAuthView: 'views/logistics/logisticsAuth/index',
AddrManageView: 'views/logistics/addrManage/index',
FeeTemplateView: 'views/logistics/feeTemplate/index'
}
function loadPageByRoutes (viewPath) {
const str = constantRouterComponents[viewPath]
console.log(str)
return function (resolve) {
require([`@/${str}.vue`], resolve)
}
}
- 錯(cuò)誤寫法:(看著一樣叼耙,就是報(bào)錯(cuò)鼻疮,一定要以
@ + 路徑名 + .vue
格式)
export default {
LogisticsAuthView: '@/views/logistics/logisticsAuth/index.vue',
AddrManageView: '@/views/logistics/addrManage/index.vue',
FeeTemplateView: '@/views/logistics/feeTemplate/index.vue'
}
function loadPageByRoutes (viewPath) {
const str = constantRouterComponents[viewPath]
console.log(str)
return function (resolve) {
require([`${str}`], resolve)
}
}
const routeArr = [
{
// 物流
path: '/logistics',
component: resolve => require(['@/layouts/RouteView'], resolve),
redirect: '/logistics/logistics-auth',
name: 'Logistics',
meta: { title: '物流', icon: 'transaction', keepAlive: true },
hidden: false,
children: [
{
path: '/logistics/logistics-auth',
redirect: '',
component: resolve => require(['@/views/logistics/addrManage'], resolve),
name: 'LogisticsAuth',
meta: { title: '物流授權(quán)', icon: 'transaction', keepAlive: true },
hidden: false,
children: null
},
{
path: '/logistics/addr-manage',
redirect: '',
component: resolve => require(['@/views/logistics/logisticsAuth'], resolve),
name: 'AddrManage',
meta: { title: '地址管理', icon: 'transaction', keepAlive: true },
hidden: false,
children: null
},
{
path: '/logistics/fee-template',
redirect: '',
component: resolve => require(['@/views/logistics/feeTemplate'], resolve),
name: 'FeeTemplate',
meta: { title: '運(yùn)費(fèi)模板', icon: 'transaction', keepAlive: true },
hidden: false,
children: null
}
]
}
]
this.$router.addRoute(...routeArr)
const routeObj = {
path: '/logistics/addr-manage',
name: 'AddrManage',
redirect: '',
meta: { title: '地址管理', icon: 'transaction', keepAlive: true },
component: resolve => require(['@/views/logistics/logisticsAuth'], resolve), // import('../test/test.vue') resolve => require(['@/views/logistics/logisticsAuth'], resolve)
hidden: false,
children: null
}
this.$router.addRoute(routeObj)