42 lines
2.2 KiB
TypeScript

import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import DashboardView from '../views/dashboard/DashboardView.vue'
import PracticeView from '../views/practice/PracticeView.vue'
import MockView from '../views/mock/MockView.vue'
import PlanView from '../views/plan/PlanView.vue'
import PlanReviewView from '../views/plan/PlanReviewView.vue'
import NewsView from '../views/news/NewsView.vue'
import NewsDetailView from '../views/news/NewsDetailView.vue'
import ProfileView from '../views/profile/ProfileView.vue'
import QuestionsView from '../views/questions/QuestionsView.vue'
import SettingsView from '../views/settings/SettingsView.vue'
export const routes: RouteRecordRaw[] = [
{ path: '/', name: 'dashboard', component: DashboardView, meta: { title: '数据中枢' } },
{ path: '/practice', name: 'practice', component: PracticeView, meta: { title: '刷题中心' } },
{ path: '/practice/wrong', name: 'practice-wrong', component: PracticeView, meta: { title: '错题本' } },
{ path: '/practice/essay', name: 'practice-essay', component: PracticeView, meta: { title: '申论' } },
{ path: '/mock', name: 'mock', component: MockView, meta: { title: '模考分析' } },
{ path: '/plan', name: 'plan', component: PlanView, meta: { title: '备考计划' } },
{ path: '/plan/review', name: 'plan-review', component: PlanReviewView, meta: { title: '周报复盘' } },
{ path: '/news', name: 'news', component: NewsView, meta: { title: '要闻' } },
{ path: '/news/:id', name: 'news-detail', component: NewsDetailView, meta: { title: '要闻详情' } },
{ path: '/profile', name: 'profile', component: ProfileView, meta: { title: '我的' } },
{ path: '/questions', name: 'questions', component: QuestionsView, meta: { title: '题库管理' } },
{ path: '/settings', name: 'settings', component: SettingsView, meta: { title: '设置' } },
{ path: '/:pathMatch(.*)*', redirect: '/' }
]
const router = createRouter({
history: createWebHistory(),
routes,
scrollBehavior: () => ({ top: 0 })
})
router.afterEach((to) => {
const title = to.meta.title as string | undefined
document.title = title ? `${title} · 备考通` : '备考通'
})
export default router