JavaScript
1
Вклад в тег
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: "/",
name: "home",
component: home,
meta: {
auth: true,
},
},
{
path: "/auth",
name: "auth",
component: () => import("@/views/auth.vue"),
},
],
})
router.beforeEach(async (to, from, next)=> {
if (to.meta.auth) {
const result = await http.get("/auth/check");
if (result.data.message === "ok") {
next()
} else {
next("/auth");
}
}
});
export default router;