vue路由优化
文章目录
很多小伙伴写的路由都是直接在路由文件里面编写,这样会导致路由文件经常出现上千行的情况,整个文件会非常地繁琐。
我们可以新建一个路由文件夹
然后在里面引入
export default{
path: '/index',
name: 'index',
component: ()=> import('../view/index.vue'),
children: [
// 子路由
]
}
然后在总路由index.js里引入
const routerList = [];
function importAll (route){
route.keys().forEach(
(key) => routerList.push(route(key).default)
);
}
importAll(require.context('./', true, /\.routes\.js/));
const routes = [
{
path:
name:
conmponent:
},
...routerList,
]
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论