@DarkLite1
index.js
// ...
import makeRoutes from './routes'
// ...
export default function ({ store /* ,ssrContext */ }) {
const routes = makeRoutes(store)
return new VueRouter({
scrollBehavior: () => ({ x: 0, y: 0 }),
routes,
// ...
})
}
routes.js
const makeRoutes = (store) => {
const routes = [
{
path: '/',
beforeEnter: (to, from, next) => {
if (!store.state.auth.token) {
next({ path: '/login' })
} else {
next()
}
},
component: () => import('layouts/MainLayout.vue'),
children: [
{ path: '', component: () => import('pages/Index.vue') },
{ path: 'about', component: () => import('pages/About.vue') }
]
}
]
// Always leave this as last one
if (process.env.MODE !== 'ssr') {
routes.push({
path: '*',
component: () => import('pages/Error404.vue')
})
}
return routes
}
export default makeRoutes