路由文件:index.ts
/* * @Author: 代码侠 * @Date: 2022-12-05 14:16:23 * @Email: achao@achao.cc * @LastEditTime: 2022-12-12 17:55:42 * @Mobile: 18000599588 */ import { createRouter, createWebHistory } from "vue-router"; import { HtmlRouter } from "./HtmlRouter"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: "/", name: "home", meta: { title: "首页" }, component: () => import("@/views/Index/IndexView.vue"), }, { path: "/about", name: "about", meta: { title: "关于我们" }, component: () => import("@/views/About/IndexView.vue"), }, { path: "/html", name: "html", meta: { title: "前端" }, component: () => import("@/views/Html/IndexView.vue"), children: HtmlRouter, }, ], }); router.beforeEach((to, from, next) => { window.document.title = to.meta.title as string; next(); }); export default router;