68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
// 主页面容器
|
|
const IndexPage = () => import('../pages/index/index.vue')
|
|
const LoginPage = () => import('../pages/login/login.vue')
|
|
const TestNameLivePage = () => import('../pages/test-name-live/test-name-live.vue')
|
|
const UserAgreementPage = () => import('../components/screens/UserAgreement.vue')
|
|
const PrivacyPolicyPage = () => import('../components/screens/PrivacyPolicy.vue')
|
|
|
|
const routes = [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: LoginPage
|
|
},
|
|
{
|
|
path: '/',
|
|
name: 'Index',
|
|
component: IndexPage
|
|
},
|
|
{
|
|
path: '/user-agreement',
|
|
name: 'UserAgreement',
|
|
component: UserAgreementPage
|
|
},
|
|
{
|
|
path: '/privacy-policy',
|
|
name: 'PrivacyPolicy',
|
|
component: PrivacyPolicyPage
|
|
},
|
|
{
|
|
path: '/home',
|
|
redirect: '/'
|
|
},
|
|
{
|
|
path: '/test-name-live',
|
|
name: 'TestNameLive',
|
|
component: TestNameLivePage
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
redirect: '/'
|
|
}
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes
|
|
})
|
|
|
|
// 路由错误处理
|
|
router.onError((error) => {
|
|
console.error('Router error:', error)
|
|
})
|
|
|
|
// 路由守卫 - 处理未匹配的路由
|
|
router.beforeEach((to, _from, next) => {
|
|
// 如果路由不存在,重定向到首页
|
|
if (!to.matched.length) {
|
|
console.warn(`Route not found: ${to.path}, redirecting to /`)
|
|
next('/')
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
|
|
export default router
|