mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 00:53:54 +08:00
fix: 修复webUI刷新跳转登录页面的问题
This commit is contained in:
@@ -1,5 +1,58 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
import Login from './components/Login.vue'
|
||||
import Panel from './components/panel.vue'
|
||||
import MainPage from './components/Main.vue'
|
||||
import RoleSetting from './components/RoleSetting.vue'
|
||||
import Registration from './components/Registration.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
component: Login,
|
||||
name: 'login'
|
||||
},
|
||||
{
|
||||
path: '/register',
|
||||
component: Registration,
|
||||
name: 'register'
|
||||
},
|
||||
{
|
||||
path: '/panel',
|
||||
component: Panel,
|
||||
name: 'panel',
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/role-setting/:deviceId',
|
||||
component: RoleSetting,
|
||||
name: 'role-setting',
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: MainPage,
|
||||
name: 'main',
|
||||
meta: { requiresAuth: true }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
|
||||
if (to.meta.requiresAuth && !isLoggedIn) {
|
||||
next('/login')
|
||||
} else if (to.path === '/login' && isLoggedIn) {
|
||||
next('/panel')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(router)
|
||||
app.mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user