import { createRouter, createWebHistory } from 'vue-router' import { defineAsyncComponent } from 'vue' // import Home from '@/views/Home.vue' // import HomeView from '@/views/HomeView.vue' //路由异步加载 //主页框架 const Home = () => import('@/views/Home.vue') //首页详细内容 const HomeView = () => import('@/views/HomeView.vue') //科普内容 const PopularizationScience = () => import('@/views/PopularizationScience.vue') const Community = () => import('@/views/Community.vue') // 组件异步懒加载方法 // const _import = (path: string) => // defineAsyncComponent(() => import(`../views/${path}.vue`)) const routes = [ { path: '/', name: 'home', // component: Home, component: Home, redirect: "/homeView", children: [{ path: 'homeView', name: 'homeView', component: HomeView // component: _import('HomeView') }, { path: 'popularizationScience', name: 'popularizationScience', component: PopularizationScience }, { path: 'community', name: 'community', component: () => import('@/views/Community.vue') }, { path: 'plan', name: 'plan', component: () => import('@/views/Plan.vue') }, { path: 'testRecord', name: 'testRecord', component: () => import('@/views/TestRecord.vue') }, { path: 'report/:planId/:flag/:name', name: 'report', component: () => import('@/views/Report.vue') }, { path: 'login', name: 'login', component: () => import('@/views/Login.vue') }, { path: 'updatePas', name: 'updatePas', component: () => import('@/views/UpdatePas.vue') }, { path: 'register', name: 'register', component: () => import('@/views/Register.vue') }, { path: 'scale/:planId/:planName/:flag/:flagName/:isComplate', name: 'scale', component: () => import('@/views/Scale.vue') }, //量表或认知任务详情页 { path: 'scaleDetail/:planId/:planName/:flag/:type', name: 'scaleDetail', component: () => import('@/views/ScaleDetail.vue') }, { path: 'scaleMid/:planId/:planName/:flag/:flagName/:num', name: 'scaleMid', component: () => import('@/views/ScaleMid.vue')//量表中间件 }, //认知任务 { path: 'cognize/:planId/:planName/:flag/:type', name: 'cognize', component: () => import('@/views/Cognize.vue') } ] // component: HomeView }, { path: '/cognizeGoNoGo/:currentType/:planId/:planName/:flag/:flagName/:num', name: 'cognizeGoNoGo', component: () => import('@/views/CognizeGoNoGo.vue') }, { path: '/cognizeFaceDot/:planId/:planName/:flag/:flagName/:formalTest', name: 'cognizeFaceDot', component: () => import('@/views/CognizeFaceDot.vue') }, { path: '/shapeIntuition_random/:planId/:planName/:flag/:flagName:/:formalTest', name: 'shapeIntuitionRandom', component: () => import('@/views/shapeIntuition_random.vue') }, { path: '/ETBexperiment_new/:planId/:planName/:flag/:flagName:/:formalTest', name: 'ETBexperimentNew', component: () => import('@/views/ETBexperiment_new.vue') }, { path: '/Stroop/:planId/:planName/:flag/:flagName:/:formalTest', name: 'Stroop', component: () => import('@/views/Stroop.vue') } ] const router = createRouter({ // history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory("/highLevelIntellectual/"), //highLevelIntellectual // history: createWebHistory('/pc/'), routes }) //页面滚动到最顶部 router.beforeEach((to, from, next) => { window.scrollTo(0, 0); /** meta是定义路由时路由的属性 */ if (to.meta.title) { (document as any).title = to.meta.title; } next(); }); export default router