You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wondering how to handle redirects for the login page if a user is already logged in.
My login page is using the path / so if the domain is reached with nothing else than the domain name the user lands on the login page.
Once logged in, the user is redirected to dashboard view. If the user logs out then redirect to the login page accurs.
So far so good, but what about if the user tries to reach the login page while he's already logged in?
this is my router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import Meta from 'vue-meta'
import NotFound from '@/components/NotFound'
import globals from '@/globals'
// Layouts
import Layout1 from '@/layout/Layout1'
Vue.use(Router)
Vue.use(Meta)
const router = new Router({
base: '/',
mode: 'history',
routes: [
{
name: 'login',
path: '/',
component: () => import('@/components/auth/LoginPage'),
meta: {
title: 'Acceso al Sistema',
auth: false
}
},
{
path: '/',
component: Layout1,
children: [
{
name: 'dashboard',
path: 'dashboard',
component: () => import('@/components/Home'),
meta: {
title: 'Inicio',
auth: true
}
},
{
name: 'sample',
path: 'sample',
component: () => import('@/components/Page2'),
meta: {
title: 'Sample',
auth: true
}
}
]
},
{
// 404 Not Found page
path: '*',
component: NotFound
}
]
})
router.afterEach(() => {
// On small screens collapse sidenav
if (window.layoutHelpers && window.layoutHelpers.isSmallScreen() && !window.layoutHelpers.isCollapsed()) {
setTimeout(() => window.layoutHelpers.setCollapsed(true, true), 10)
}
// Scroll to top of the page
globals().scrollTop(0, 0)
})
router.beforeEach((to, from, next) => {
// Set loading state
document.body.classList.add('app-loading')
// Add tiny timeout to finish page transition
setTimeout(() => next(), 10)
})
export default router
I tried by adding redirect: 'dashboard' to the login route which works as expected, if a user is already logged in it's redirected to the dashboard, but if the user is not logged in then I face a blank page.
I can't figure out what am I doing wrong
EDIT 1
I did the same question for a previous version, but I'm still facing the same issue: #493 (comment)
EDIT 2
I found that notFoundRedirect is triggered when a logged in user is trying to reach an auth: false route, but what's the correct way to define it? Can I specify a notFoundRedirect only for login route like
I'm wondering how to handle redirects for the login page if a user is already logged in.
My login page is using the path
/
so if the domain is reached with nothing else than the domain name the user lands on the login page.Once logged in, the user is redirected to dashboard view. If the user logs out then redirect to the login page accurs.
So far so good, but what about if the user tries to reach the login page while he's already logged in?
this is my router/index.js
This is my main.js
I tried by adding
redirect: 'dashboard'
to the login route which works as expected, if a user is already logged in it's redirected to the dashboard, but if the user is not logged in then I face a blank page.I can't figure out what am I doing wrong
EDIT 1
I did the same question for a previous version, but I'm still facing the same issue: #493 (comment)
EDIT 2
I found that
notFoundRedirect
is triggered when a logged in user is trying to reach anauth: false
route, but what's the correct way to define it? Can I specify anotFoundRedirect
only for login route likeThe text was updated successfully, but these errors were encountered: