Files
cz-web/src/router/guard.ts
2026-10-01 17:24:57 +08:00

23 lines
583 B
TypeScript

import type { Router } from 'vue-router'
import { storage } from '@/utils/storage'
export function setupGuard(router: Router): void {
router.beforeEach((to) => {
if (
import.meta.env.DEV
&& new URLSearchParams(window.location.search).has('visual')
) {
return true
}
if (to.meta.requiresAuth && !storage.get<string>('token')) {
return { path: '/login', query: { redirect: to.fullPath } }
}
return true
})
router.afterEach((to) => {
document.title = to.meta.title ? `${to.meta.title} - 虫子智造` : '虫子智造'
})
}