From 6a81c1686febbe9cc081b23402eeb858c6760335 Mon Sep 17 00:00:00 2001 From: Dede Fuji Abdul Date: Thu, 2 Nov 2023 11:11:38 +0700 Subject: [PATCH] Redirect root path to Home component --- src/router/index.ts | 66 ++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 487bd81..285df65 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -700,8 +700,10 @@ export const routes: RouteRecordRaw[] = [ component: NotFoundView }, { - path: ':pathMatch(.*)*', - redirect: '/404' + path: '/', + redirect: { + name: 'Home' + } } ] @@ -805,48 +807,32 @@ router.beforeEach((to, from, next) => { const auth = useAuthStore(); // if to is not found, redirect to 404 - // if (to.matched.length === 0) { - // if (to.path === '/') { - // if (auth.isLoggedIn) { - // next('/home') - // } else { - // next('/login') - // } - // } else { - // next('/404') - // } - // } else { - // // if to is not login and user is not logged in, redirect to login - // if (auth.isLoggedIn) { - // // if to is login and user is logged in, redirect to home - // if (to.path === '/login') { - // next('/home') - // } else { - // next() - // } - // } else { - // // if to is 404, redirect to 404 - // if (to.path !== '/404' && to.path !== '/login') { - // next('/login') - // } else { - // next() - // } - // } - // } - - if (auth.isLoggedIn) { - // if to is login and user is logged in, redirect to home - if (to.path === '/login') { - next('/home') + if (to.matched.length === 0) { + if (to.path === '/') { + if (auth.isLoggedIn) { + next('/home') + } else { + next('/login') + } } else { - next() + next('/404') } } else { - // if to is 404, redirect to 404 - if (to.path !== '/404' && to.path !== '/login') { - next('/login') + // if to is not login and user is not logged in, redirect to login + if (auth.isLoggedIn) { + // if to is login and user is logged in, redirect to home + if (to.path === '/login') { + next('/home') + } else { + next() + } } else { - next() + // if to is 404, redirect to 404 + if (to.path !== '/404' && to.path !== '/login') { + next('/login') + } else { + next() + } } } })