Former-commit-id: 935ee3c7cceb4deb31965501a80c202a0034da52 [formerly 3a68553e1ac0af9dad51bd2b8eab1152959a4dc2] [formerly 596f9d6676cceafac0e9fe66a9137683482c2685 [formerly 191b31e9774be6e9a2a12a8336db40fe14eb94b5]] Former-commit-id: f0179a58c53f057f1b6f0f19b40fc2308b0edd15 [formerly 5151c85d599e8b3772dabab24973004105c29881] Former-commit-id: c28c7b95e5ea1b1d9ae2af046f49cc5ffa848385
74 lines
1.4 KiB
JavaScript
74 lines
1.4 KiB
JavaScript
import Vue from 'vue'
|
|
import Router from 'vue-router'
|
|
import Login from '@/components/Login'
|
|
import Files from '@/components/Files'
|
|
import Main from '@/components/Main'
|
|
import auth from '@/utils/auth.js'
|
|
|
|
Vue.use(Router)
|
|
|
|
const router = new Router({
|
|
base: document.querySelector('meta[name="base"]').getAttribute('content'),
|
|
mode: 'history',
|
|
routes: [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: Login,
|
|
beforeEnter: function (to, from, next) {
|
|
auth.loggedIn()
|
|
.then(() => {
|
|
next({ path: '/files' })
|
|
})
|
|
.catch(() => {
|
|
document.title = 'Login'
|
|
next()
|
|
})
|
|
}
|
|
},
|
|
{
|
|
path: '/*',
|
|
component: Main,
|
|
meta: {
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '/files*',
|
|
name: 'Files',
|
|
component: Files
|
|
},
|
|
{
|
|
path: '/*',
|
|
redirect: {
|
|
name: 'Files'
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.matched.some(record => record.meta.requiresAuth)) {
|
|
// this route requires auth, check if logged in
|
|
// if not, redirect to login page.
|
|
auth.loggedIn()
|
|
.then(() => {
|
|
next()
|
|
})
|
|
.catch(e => {
|
|
next({
|
|
path: '/login',
|
|
query: { redirect: to.fullPath }
|
|
})
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
next()
|
|
})
|
|
|
|
export default router
|