1.单独路由界面(例如:router/other.js)
export default [
// 登录页面
{
path: "/",
name: "login",
component: () => import("@/views/login"),
meta: {
title: "登录"
}
},
// 首页
{
path: "/home",
name: "home",
component: () => import("@/views/home"),
meta: {
title: "首页"
}
}
];
2.主路由:index.js
import Vue from "vue";
import Router from "vue-router";
import other from "./other";
Vue.use(Router);
// 路由配置
const router = new Router({
mode: "hash",
base: process.env.BASE_URL,
routes: [...other]
});
// 设置页面title
router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
if (to.meta.title) {
document.title = to.meta.title;
}
next();
});
export default router;