Files
asco_admin/src/router.js
T
2022-01-13 12:39:52 +03:30

196 lines
5.6 KiB
JavaScript

import Vue from 'vue'
import Router from 'vue-router'
import 'firebase/auth'
import store from "./store/store";
Vue.use(Router)
const router = new Router({
mode: 'history',
base: process.env.BASE_URL,
scrollBehavior() {
return {x: 0, y: 0}
},
routes: [
{
path: '/auth',
component: () => import('@/layouts/full-page/FullPage.vue'),
children: [
{
path: '/auth/login',
name: 'auth-login',
component: () => import('./views/auth/Login.vue'),
meta: {
rule: 'editor'
}
},
{
path: '/register/form',
name: 'auth-register',
component: () => import('./views/register/Register.vue'),
meta: {
rule: 'editor'
}
},
// {
// path: '/auth/forgot-password',
// name: 'auth-forget',
// component: () => import('@/views/auth/ForgotPassword.vue'),
// meta: {
// rule: 'editor'
// }
// },
]
},
{
path: '',
component: () => import('./layouts/main/Main.vue'),
children: [
{
path: '/',
name: 'dashboard',
redirect: '/dashboard',
meta: {
rule: 'editor'
}
},
{
path: '/dashboard',
name: 'dashborrdPage',
component: () => import('./views/dashboard/DashboardAnalytics.vue'),
meta: {
rule: 'editor'
}
},
{
path: '/config',
name: 'config',
component: () => import('./views/config/Config.vue'),
meta: {
rule: 'editor',
parent: 'main'
}
},
{
path: '/proposal',
name: 'proposal',
component: () => import('./views/proposal/Proposal.vue'),
meta: {
rule: 'editor',
parent: 'main'
}
},
{
path: '/personel',
name: 'personel',
component: () => import('./views/personel/Personel.vue'),
meta: {
rule: 'editor',
parent: 'main'
}
},
{
path: '/users',
name: 'users',
component: () => import('./views/users/users.vue'),
meta: {
rule: 'editor',
parent: 'main'
}
},
{
path: '/register/users',
name: 'register-users',
component: () => import('./views/users/create.vue'),
meta: {
rule: 'editor',
parent: 'main'
}
},
{
path: '/register/personnel',
name: 'register-personnel',
component: () => import('./views/register/RegisterPersonnel.vue'),
meta: {
rule: 'editor',
parent: 'main'
}
},
{
path: '/permission',
name: 'permission',
component: () => import('./views/permission/Access.vue'),
meta: {
rule: 'editor',
parent: 'main'
}
},
]
},
{
path: '/pages/error-404',
name: 'error-404',
component: () => import('./views/pages/Error404'),
meta: {
rule: 'editor'
}
},
{
path: '/pages/error-403',
name: 'error-403',
component: () => import('./views/pages/NotAuthorized'),
meta: {
rule: 'editor'
}
},
{
path: '*',
redirect: '/pages/error-404'
}
],
})
router.afterEach((to) => {
const appLoading = document.getElementById('loading-bg')
if (appLoading) {
appLoading.style.display = "none";
}
})
router.beforeEach(async (to, from, next) => {
// return next();
let isLogin = sessionStorage.getItem('accessToken');
await store.commit('route/SET_ROUTE',to.path)
//console.log("to.path ==> ", to.path);
if (
to.path === "/register/form" ||
to.path === "/auth/login" ||
to.path === "/auth/register" ||
to.path === "/pages/error-404" ||
to.path === "/pages/error-403" ||
to.path === "/auth/forgot-password"
) {
/* if (isLogin) {
router.push({path: '/'});
}*/
return next();
}
else if (!isLogin) {
router.push({path: '/auth/login'});
return;
} else {
return next();
}
});
export default router