From 487997b87cbdaffac74f6ca899a9319c34b98e8f Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Mon, 9 Jan 2023 15:10:05 +0800 Subject: [PATCH] Adding a less complex router --- src/router/index.ts | 47 ++++++++++---------------------- src/views/NewEditProjectView.vue | 9 ++++-- src/views/ProjectViewView.vue | 7 ++++- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 9697d48..38611c9 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -7,13 +7,19 @@ const routes: Array = [ name: "home", component: () => import(/* webpackChunkName: "start" */ "../views/DiscoverView.vue"), + beforeEnter: (to, from, next) => { + const appStore = useAppStore(); + const isAuthenticated = appStore.condition === "registered"; + if (isAuthenticated) { + next(); + } else { + next({ name: "start" }); + } + }, }, { path: "/about", name: "about", - // route level code-splitting - // this generates a separate chunk (about.[hash].js) for this route - // which is lazy-loaded when the route is visited. component: () => import(/* webpackChunkName: "about" */ "../views/AboutView.vue"), }, @@ -75,6 +81,12 @@ const routes: Array = [ /* webpackChunkName: "new-edit-commitment" */ "../views/NewEditCommitmentView.vue" ), }, + { + path: "/project", + name: "project", + component: () => + import(/* webpackChunkName: "project" */ "../views/ProjectViewView.vue"), + }, { path: "/new-edit-project", name: "new-edit-project", @@ -83,12 +95,6 @@ const routes: Array = [ /* webpackChunkName: "new-edit-project" */ "../views/NewEditProjectView.vue" ), }, - { - path: "/project", - name: "project", - component: () => - import(/* webpackChunkName: "project" */ "../views/ProjectViewView.vue"), - }, { path: "/projects", name: "projects", @@ -111,27 +117,4 @@ const router = createRouter({ routes, }); -router.beforeEach(async (to, from, next) => { - const publicPages = ["/start", "/account", "/import-account"]; - const isPublic = publicPages.includes(to.path); - const appStore = useAppStore(); - console.log(to); - if (to.path === "/" && appStore.condition === "registered") { - next({ path: "/account" }); - } else if (isPublic) { - switch (appStore.condition) { - case "registered": - next(); - break; - default: - next(); - break; - } - } else if (appStore.condition === "uninitialized") { - next({ path: "/start" }); - } else { - next(); - } -}); - export default router; diff --git a/src/views/NewEditProjectView.vue b/src/views/NewEditProjectView.vue index bff74d3..545e3e1 100644 --- a/src/views/NewEditProjectView.vue +++ b/src/views/NewEditProjectView.vue @@ -10,7 +10,6 @@ class="text-lg text-center px-2 py-1 absolute -left-2 -top-1" > - [New/Edit] Project @@ -39,7 +38,7 @@ type="text" placeholder="Project Name" class="block w-full rounded border border-slate-400 mb-4 px-3 py-2" - v-modal="projectName" + v-model="projectName" />