1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| // src/router/index.js import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
const webTitle = "關於Lara || ";
const options = { // history: createWebHashHistory(), history: createWebHistory(),//井字號會不顯示 routes:[ { path: '/', name:'首頁', component: () => import("@/views/Home/index.vue"), meta:{title:webTitle+'首頁'} }, { path: '/about', name:'關於我們', component: () => import("@/views/AboutMe/index.vue"), meta:{title:webTitle+'關於我們'} }, { path: '/:catchAll(.*)', name: '404', component: () => import('../views/errorPage/404.vue'), meta: { title:webTitle+'404' }, } ], }
const router = createRouter(options) // 導航守衛 router.beforeEach( (to, from, next) => { // webTitle document.title = to.meta.title || webTitle + '首頁'; next(); })
// 輸出router export default router
|