Files
xl-root/src/router/index.js

25 lines
670 B
JavaScript
Raw Normal View History

2025-05-27 19:01:22 +08:00
import {createRouter, createWebHistory} from 'vue-router';
2025-02-27 14:38:47 +08:00
import routes from "./routes.js";
import {useUserStore} from "../pinia/UserStore/index.js";
2025-03-10 19:01:21 +08:00
import {useSystemStore} from "../pinia/SystemStore/index.js";
2025-02-27 14:38:47 +08:00
const router = createRouter({
2025-05-27 19:01:22 +08:00
history: createWebHistory(),
2025-02-27 14:38:47 +08:00
routes,
})
router.beforeEach((to, from, next) => {
const {isLogin} = useUserStore();
2025-03-10 19:01:21 +08:00
const SystemStore = useSystemStore();
2025-02-28 09:56:01 +08:00
if (!isLogin && !to.path.includes('loginSYS')) {
2025-05-27 19:01:22 +08:00
next({path: '/loginSYS'});
2025-02-27 14:38:47 +08:00
} else {
2025-05-27 19:01:22 +08:00
SystemStore.NOW_ROUTER = to.path;
Object.assign(SystemStore.NOW_ROUTER_QUERY, to.query);
2025-02-27 14:38:47 +08:00
next();
}
});
export default router;