👀前端 小伙伴们,在日常开发中,会遇到非常多的路由【10-100 等等】;这个时候就需要我们把路由进行模块化拆分👇 👇 👇
一📌未拆分前结构 :
一🍖1、新建子模块navbar目录
在src 下的 router目录中 新建 navbar目录 创建 index.js
一🥪2、新建子模块index.js
export default [
{
path: "/",
name: "home",
component: () => import( "@/views/Home.vue"),
},
{
path: "/about",
name: "about",
component: () =>
import( "@/views/About.vue"),
},
{
path: "/demo",
name: "demo",
component: () => import( "@/views/demo"),
},
{
path: "/elementary",
name: "elementary",
component: () =>
import( "@/views/Elementary.vue"),
},
{
path: "/middlerank",
name: "middlerank",
component: () =>
import( "@/views/Middlerank.vue"),
},
{
path: "/advanced",
name: "advanced",
component: () =>
import( "@/views/Advanced.vue"),
},
];
一🍦3、将模块引入到 router.js 中
import Navbar from "./router/navbar/index";
...
export default new Router({
mode: "history",
base: process.env.BASE_URL,
routes: [
...Navbar,
],
});
模块拆分完成 -拆分更多模块,方法同上述步骤。一🐱?🐉
|