初始化2

This commit is contained in:
SunYF
2026-08-28 15:06:01 +08:00
parent b34325a16f
commit a9c3fbeb41
537 changed files with 176215 additions and 17 deletions
@@ -0,0 +1,31 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import { getToken } from '../utils/request'
// hash 路由:静态托管下刷新/深链稳定,不需要服务端兜底配置
const routes = [
{ path: '/', redirect: '/main' },
{
path: '/login',
name: 'Login',
component: () => import('../views/Login.vue')
},
{
path: '/main',
name: 'Main',
component: () => import('../views/Main.vue')
}
]
const router = createRouter({
history: createWebHashHistory(),
routes
})
router.beforeEach((to) => {
const hasToken = !!getToken()
if (!hasToken && to.path !== '/login') return '/login'
if (hasToken && to.path === '/login') return '/main'
return true
})
export default router