2024-03-28 06:08:17 +00:00
|
|
|
import { createRouter, createWebHistory } from "vue-router";
|
|
|
|
|
2024-03-28 08:48:13 +00:00
|
|
|
import {useUserStore} from "@/stores/user";
|
2024-03-28 06:08:17 +00:00
|
|
|
const routes = [
|
|
|
|
{
|
|
|
|
path: "/",
|
|
|
|
name: "home",
|
|
|
|
meta: {
|
|
|
|
auth: true,
|
|
|
|
},
|
|
|
|
// route level code-splitting
|
|
|
|
// this generates a separate chunk (Home-[hash].js) for this route
|
|
|
|
// which is lazy-loaded when the route is visited.
|
|
|
|
component: () => import("@/views/Home.vue"),
|
|
|
|
},
|
2024-03-28 08:48:13 +00:00
|
|
|
{
|
|
|
|
path: "/auth/login",
|
|
|
|
name: "login",
|
|
|
|
meta: {
|
|
|
|
auth: false,
|
|
|
|
},
|
|
|
|
// route level code-splitting
|
|
|
|
// this generates a separate chunk (Home-[hash].js) for this route
|
|
|
|
// which is lazy-loaded when the route is visited.
|
|
|
|
component: () => import("@/views/auth/Login.vue"),
|
|
|
|
},
|
2024-03-28 06:08:17 +00:00
|
|
|
|
2024-03-28 11:23:23 +00:00
|
|
|
{
|
|
|
|
path: "/spiders",
|
|
|
|
name: "spiders.index",
|
|
|
|
meta: {
|
|
|
|
auth: false,
|
|
|
|
},
|
|
|
|
// route level code-splitting
|
|
|
|
// this generates a separate chunk (Home-[hash].js) for this route
|
|
|
|
// which is lazy-loaded when the route is visited.
|
|
|
|
component: () => import("@/views/spiders/List.vue"),
|
|
|
|
},
|
|
|
|
|
2024-03-28 06:08:17 +00:00
|
|
|
];
|
2024-03-18 08:55:04 +00:00
|
|
|
|
|
|
|
const router = createRouter({
|
2024-03-28 06:08:17 +00:00
|
|
|
history: createWebHistory(process.env.BASE_URL),
|
|
|
|
routes,
|
|
|
|
});
|
|
|
|
|
2024-03-28 08:48:13 +00:00
|
|
|
router.beforeEach((to: any, from: any) => {
|
|
|
|
console.log(from.name, from.fullPath)
|
|
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
|
|
// if (to.matched.length === 0) {
|
|
|
|
// return router.push({ name: "errors.404" });
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (to.meta.auth == true) {
|
|
|
|
// validate login state
|
|
|
|
if (userStore.access_token == null) {
|
|
|
|
router.push({name: "login"}).then(r => {
|
|
|
|
console.log(r)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2024-03-26 03:19:47 +00:00
|
|
|
|
2024-03-28 06:08:17 +00:00
|
|
|
export default router;
|