I’m having problems customizing the routes.js. I would like to go directly to the login (Login.vue) when I initially call it with / or /login. How can I customize the default routes.js correctly? The app always goes to the dashboard first.
const routes = [
{
path: '/',
redirect: 'dashboard',
component: DashboardLayout,
children: [
{
path: '/dashboard',
name: 'dashboard',
// 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: "demo" */ '../views/Dashboard.vue')
},
{
path: '/icons',
name: 'icons',
component: () => import(/* webpackChunkName: "demo" */ '../views/Icons.vue')
},
{
path: '/profile',
name: 'profile',
component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/UserProfile.vue')
},
{
path: '/maps',
name: 'maps',
component: () => import(/* webpackChunkName: "demo" */ '../views/GoogleMaps.vue')
},
{
path: '/tables',
name: 'tables',
component: () => import(/* webpackChunkName: "demo" */ '../views/RegularTables.vue')
}
]
},
{
path: '/',
redirect: 'login',
component: AuthLayout,
children: [
{
path: '/login',
name: 'login',
component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/Login.vue')
},
{
path: '/register',
name: 'register',
component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/Register.vue')
},
{ path: '*', component: NotFound }
]
}
];
2
Answers
The process should be an automatic referral to the dashboard and within Dashboard.vue you check if the customer is inside and if not you direct them to the login
Because you wrote above that if the slash was empty, it would first go to the dashboard and ignore the login, usually the redirection to the login is done with guards or check in your dashboard component and not in route.js