chore
This commit is contained in:
@@ -1,8 +1,65 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [],
|
||||
})
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
component: () => import('@/pages/login-page.vue'),
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layouts/app-layout.vue'),
|
||||
redirect: '/dashboard',
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
component: () => import('@/pages/dashboard-page.vue'),
|
||||
},
|
||||
{
|
||||
path: 'device',
|
||||
component: () => import('@/pages/device-page.vue'),
|
||||
},
|
||||
{
|
||||
path: 'alarm',
|
||||
component: () => import('@/pages/alarm-page.vue'),
|
||||
},
|
||||
{
|
||||
path: 'statistics',
|
||||
component: () => import('@/pages/statistics-page.vue'),
|
||||
},
|
||||
{
|
||||
path: 'log',
|
||||
component: () => import('@/pages/log-page.vue'),
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'NotFound',
|
||||
component: () => import('@/pages/not-found-page.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default router
|
||||
const whiteList = ['/login'];
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const userStore = useUserStore();
|
||||
if (userStore.userLoginResult?.token) {
|
||||
if (to.path === '/login') {
|
||||
next({ path: '/' });
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
if (whiteList.includes(to.path)) {
|
||||
next();
|
||||
} else {
|
||||
next('/login');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user