import { createWebHashHistory, createRouter, RouteRecordRaw } from 'vue-router' const Parent = () => import('@/view/layout/parent.vue') const routes: Array = [ { path: '/', name: 'layout', component: () => import('@/view/layout/index.vue'), children: [], redirect: () => { return { path: '/layout/home' } }, }, { path: '/layout', component: () => import('@/view/layout/index.vue'), children: [ { path: 'home', component: () => import('@/view/home/index.vue'), meta: { title: 'home' }, }, { path: 'Policy', component: () => import('@/view/policy/index.vue'), meta: { title: 'policy' }, }, { path: 'about', component: () => import('@/view/about/index.vue'), meta: { title: 'about' }, }, { path: 'faq', component: () => import('@/view/faq/index.vue'), meta: { title: 'faq' }, }, { path: 'contact', component: () => import('@/view/contact/index.vue'), meta: { title: 'contact' }, }, { path: 'latestArticle', component: () => import('@/view/latestArticle/index.vue'), meta: { title: 'latestArticle' }, }, { path: 'articleDetail', component: () => import('@/view/latestArticle/detail.vue'), meta: { title: 'latestArticleDetail' }, }, { path: 'podcast', component: () => import('@/view/podcast/index.vue'), meta: { title: 'podcast' }, }, ], }, { path: '/login', component: () => import('@/view/layout/login.vue'), meta: { title: 'login', auth: false }, }, //页面中的二级页面 { path: '/user', name: 'userPage', component: Parent, children: [ { path: 'detail', name: 'detail', component: () => import('@/view/user/detail.vue'), meta: { title: '用户二级页面', pass: true, }, }, ], }, { path: '/404', name: 'NotFound', component: () => import('@/view/layout/404.vue'), meta: { title: '404', auth: false, }, }, { //不存在的路由 path: '/:pathMatch(.*)', redirect: '/404', }, ] const router = createRouter({ history: createWebHashHistory(), routes, scrollBehavior(to) { if (to.hash) { return { el: to.hash, behavior: 'smooth', } } }, }) export default router