mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-08 19:22:57 +00:00

Former-commit-id: 682c7d56814a3c9a35fcf55b540e470b5c66d890 [formerly a603a591938ec8edbe3f703772f86ba978ff92de] [formerly 6d1a11fdeb5d3a00c202e125a0873b263a3787cf [formerly 12c466d2aafbd07bea83352c03d0ad19347dbea3]] Former-commit-id: 4f43bbf0b4f91a9528cdf881f4abbdfc098b82cd [formerly 7fc1e010ac54107ff03762ad729ed54beccca02c] Former-commit-id: 4d464034e98aefbdce39d142a30bf34aa3fd2d2e
78 lines
1.4 KiB
JavaScript
78 lines
1.4 KiB
JavaScript
import Vue from 'vue'
|
|
import Router from 'vue-router'
|
|
import Login from '@/components/Login'
|
|
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: '/',
|
|
redirect: {
|
|
path: '/files/'
|
|
}
|
|
},
|
|
{
|
|
path: '/*',
|
|
component: Main,
|
|
meta: {
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '/files/*',
|
|
name: '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
|