import { createRouter, createWebHistory } from 'vue-router' import Home from '../pages/Home.vue' import CourseDetail from '../pages/CourseDetail.vue' import MyLearning from '../pages/MyLearning.vue' import MyLearningHome from '../pages/MyLearningHome.vue' import Layout from '@/components/Layout.vue' const routes = [ { path: '/', name: 'Home', component: Home, redirect: '/index', meta: { title: 'route.home' }, children: [ { path: 'index', name: 'Index', component: Home, meta: { title: 'route.home' } } ] }, { path: '/search-platform', name: 'SearchPlatformHome', component:() => import('@/pages/SearchPlatform.vue'), meta: { title: 'SearchPlatformHome' }, children: [ // { // path: 'search-platform', // name: 'SearchPlatform', // component: () => import('@/pages/SearchPlatform.vue'), // meta: { title: '' } // }, { path: 'workflow-detail', name: 'WorkflowDetail', component: () => import('@/pages/WorkflowDetail.vue'), meta: { title: '' } }, { path: 'workflow-add', name: 'WorkflowAdd', component: () => import('@/pages/WorkflowAdd.vue'), meta: { title: 'common.chuangjiangongzuoliu' } } ] }, { path: '/workflow-add', name: 'WorkflowAddHome', component: () => import('@/pages/WorkflowAdd.vue'), meta: { title: 'common.chuangjiangongzuoliu' } }, { path: '/workflow-detail', name: 'WorkflowDetailHome', component: () => import('@/pages/WorkflowDetail.vue'), meta: { title: '' } }, { path: '/workflow-trade', name: 'WorkflowTradeHome', component: () => import('@/pages/workflowTrade/workflowTrade.vue'), meta: { title: 'common.gongzuoliu_trade' }, children: [ { path: 'workflow-trade-detail', name: 'WorkflowTradeDetail', component: () => import('@/pages/workflowTrade/workflowTradeDetail.vue'), meta: { title: '' } }, { path: 'workflow-trade-add', name: 'WorkflowTradeAdd', component: () => import('@/pages/workflowTrade/workflowTradeAdd.vue'), meta: { title: 'route.gongzuoliu_trade_add' } } ] }, { path: '/course/:id', name: 'CourseDetail', component: CourseDetail, meta: { title: 'route.courseDetail' } }, { path: '/my-learning', name: 'MyLearningHome', component: Layout, meta: { title: 'route.myLearning' }, children: [ { path: '', name: 'MyLearning', component: MyLearning, meta: { title: 'route.myLearning' } }, { path: 'course/:id', name: 'MyLearningCourseDetail', component: CourseDetail, meta: { title: 'route.myLearningCourseDetail' } } ] } ] const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes, // 添加scrollBehavior配置项,实现页面切换时滚轴置顶 scrollBehavior() { return { top: 0 } } }) // 全局路由守卫 router.beforeEach((to, from, next) => { console.log(33333333333, to) // 设置页面标题 // document.title = to.meta.title || 'Boom Ai' // 动态设置路由的meta.title const lastRoute = to.matched?.[to.matched.length - 1] if (lastRoute && to.query.metaTitle) { to.meta.title = to.query.metaTitle; lastRoute.meta.title = to.query.metaTitle; } next() }) export default router