Redirect root path to Home component

This commit is contained in:
Dede Fuji Abdul 2023-11-02 11:11:38 +07:00
parent d89d1b9a4e
commit 6a81c1686f

View File

@ -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()
}
}
}
})