🧑💻 新增env.dev,用于区分环境类型, dev环境忽略路由守卫
This commit is contained in:
1
frontend/.env
Normal file
1
frontend/.env
Normal file
@@ -0,0 +1 @@
|
||||
VITE_APP_ENV='prod'
|
||||
1
frontend/.env.development
Normal file
1
frontend/.env.development
Normal file
@@ -0,0 +1 @@
|
||||
VITE_APP_ENV='dev'
|
||||
@@ -3,6 +3,7 @@ import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
import { isAppInitialized } from '@/utils/config'
|
||||
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
@@ -96,6 +97,14 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
// 如果访问的不是初始化页面,且没有初始化标记,则重定向到初始化页面
|
||||
if (to.path !== '/initialization') {
|
||||
// 在开发环境下跳过初始化检查
|
||||
const isDev = import.meta.env.VITE_APP_ENV === 'dev'
|
||||
if (isDev) {
|
||||
console.log('开发环境,跳过初始化检查')
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
const initialized = await isAppInitialized()
|
||||
console.log('检查初始化状态:', initialized)
|
||||
|
||||
@@ -109,4 +118,5 @@ router.beforeEach(async (to, from, next) => {
|
||||
next()
|
||||
})
|
||||
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user