Files
Evergreen-Health-Mobile/src/router.ts
T
2026-09-22 16:55:21 +08:00

34 lines
1.2 KiB
TypeScript

import { createRouter, createWebHistory } from 'vue-router'
import AuthView from './views/AuthView.vue'
import DashboardView from './views/DashboardView.vue'
import AssessmentView from './views/AssessmentView.vue'
import ProfileView from './views/ProfileView.vue'
import DeviceControlView from './views/DeviceControlView.vue'
import { hasToken } from './services/auth'
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', redirect: '/dashboard' },
{ path: '/auth', component: AuthView, meta: { guest: true } },
{ path: '/onboarding', redirect: '/assessment' },
{ path: '/dashboard', component: DashboardView },
{ path: '/assessment', component: AssessmentView },
{ path: '/profile', component: ProfileView },
{ path: '/device-control', component: DeviceControlView }
]
})
router.beforeEach((to) => {
if (!to.meta.guest && !hasToken()) return '/auth'
if (to.meta.guest && hasToken()) return '/dashboard'
})
router.afterEach(() => {
if (typeof (window as any).WeixinJSBridge !== 'undefined' && (window as any).WeixinJSBridge.call) {
(window as any).WeixinJSBridge.call('hideToolbar')
}
})
export default router