Witajcie,
Próbuję ogarnąć Vue i trafiłem na mały problem. Robię aplikację w Laravelu oraz Vue. Mam taki kod:
import Vue from 'vue'
import Router from 'vue-router'
// Containers
const TheContainer = () => import('@/containers/TheContainer')
// Views
const Dashboard = () => import('@/views/Dashboard')
....
Vue.use(Router)
let router = new Router({
mode: 'hash', // https://router.vuejs.org/api/#mode
linkActiveClass: 'active',
scrollBehavior: () => ({ y: 0 }),
routes: configRoutes()
})
router.beforeEach((to, from, next) => {
let roles = localStorage.getItem("roles");
if(roles != null){
roles = roles.split(',')
}
if(to.matched.some(record => record.meta.requiresAdmin)) {
if(roles != null && roles.indexOf('admin') >= 0 ){
next()
}else{
next({
path: '/login',
params: { nextUrl: to.fullPath }
})
}
}else if(to.matched.some(record => record.meta.requiresUser)) {
if(roles != null && roles.indexOf('user') >= 0 ){
next()
}else{
next({
path: '/login',
params: { nextUrl: to.fullPath }
})
}
}else{
next()
}
})
export default router
function configRoutes () {
return [
{
path: '/',
redirect: '/dashboard',
name: 'Home',
component: TheContainer,
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: Dashboard
},
]
},
]
}
- Kiedy użytkownik nie jest zalogowany - ma zawsze nastąpić przekierowanie na (/login) - nie jak jest aktualnie do /dashboard
- Kiedy użytkownikowi wygaśnie sesja to jw
Jeśli użytkownik jest zalogowany, to nie ma mieć możliwości wejścia na /login, a jego główną stroną ma być /dashboard
Jak to poprawić? Z góry dziękuję za pomoc :)