Initial release
This commit is contained in:
44
src/router/index.ts
Normal file
44
src/router/index.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import ProjectList from "../views/ProjectList.vue";
|
||||
import Login from "../views/Login.vue";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL), // BASE_URL из vite.config.ts
|
||||
routes: [
|
||||
{
|
||||
path: "/login",
|
||||
name: "Login",
|
||||
component: Login,
|
||||
meta: { requiresGuest: true },
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
name: "ProjectList",
|
||||
component: ProjectList,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
// Каждый проект (доска) имеет отдельную страницу, возможно такой вариант будет лучше, особенно для больших отделений
|
||||
{
|
||||
path: "/project/:projectId",
|
||||
name: "ProjectDetails",
|
||||
component: () => import("../views/Project.vue"),
|
||||
props: true,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const authStore = useAuthStore();
|
||||
|
||||
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
|
||||
next({ name: "Login" });
|
||||
} else if (to.meta.requiresGuest && authStore.isAuthenticated) {
|
||||
next({ name: "ProjectList" });
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user