index.js 615 Bytes
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      meta: {
        title: 'SN管理'
      }
    }
  ]
})

router.beforeEach((to,from,next)=>{//beforeEach是router的钩子函数,在进入路由前执行
  if(to.meta.title){//判断是否有标题
      document.title = to.meta.title
  }
  next()  //执行进入路由,如果不写就不会进入目标页
})

export default router