-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrouter.js
150 lines (147 loc) · 4.5 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import Vue from 'vue'
import Router from 'vue-router'
import GuestLayout from './views/layouts/GuestLayout.vue'
import AuthLayout from '@/views/layouts/AuthLayout'
import AccountLayout from '@/views/layouts/account/AccountLayout'
import Approval from '@/views/Approval.vue'
import ApprovalAll from '@/views/ApprovalAll.vue'
// Authentication Pages
import E404 from '@/views/error/404'
import E503 from '@/views/error/503'
// App Pages
import Whoops from '@/views/error/Whoops'
import Dashboard from '@/views/Dashboard'
import MainMenu from '@/views/MainMenu'
import Master from '@/views/master/routes'
import HumanResource from '@/views/human-resource/routes'
import Purchase from '@/views/purchase/routes'
import Sales from '@/views/sales/routes'
import Inventory from '@/views/inventory/routes'
import Manufacture from '@/views/manufacture/routes'
import POS from '@/views/pos/routes'
import Finance from '@/views/finance/routes'
import Accounting from '@/views/accounting/routes'
import Account from '@/views/account/routes'
import Plugin from '@/views/plugin/routes'
import Setting from '@/views/setting/routes'
import store from '@/store'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/auth',
name: 'signin',
component: GuestLayout,
children: [
{ path: 'signin', name: 'sign-in', component: () => import('./views/auth/SignIn.vue') },
{ path: 'forgot-password', name: 'forgot-password', component: () => import('./views/auth/ForgotPassword.vue') },
{ path: 'reset-password', name: 'reset-password', component: () => import('./views/auth/ResetPassword.vue') }
]
},
{
path: '/account',
component: AccountLayout,
children: [
{ path: 'whoops', component: Whoops },
{ path: 'storage', name: 'storage', component: () => import('./views/Storage.vue') },
...Account
],
beforeEnter: (to, from, next) => {
// redirect to sign in page if not authenticated
if (!store.state.auth.user) {
if (Vue.cookie.get('TAT') !== null && Vue.cookie.get('TTT') !== null) {
store.dispatch('reloadVuex')
.then(response => {
next()
}).catch(error => {
console.log(error)
next('/503')
})
next()
} else {
next({ path: '/auth/signin', query: { r: to.fullPath } })
}
} else {
// redirect to account route if host is not tenant subdomain
if (window.location.host !== process.env.VUE_APP_DOMAIN) {
next('/')
} else {
next()
}
}
}
},
{
path: '/',
component: AuthLayout,
children: [
{ path: '/', name: 'dashboard', component: Dashboard },
{ path: '/menu', name: 'main-menu', component: MainMenu },
{ path: '/storage', name: 'tenant-storage', component: () => import('./views/TenantStorage.vue') },
{ path: '/whoops', component: Whoops },
...Master,
...HumanResource,
...Purchase,
...Sales,
...Inventory,
...Manufacture,
...POS,
...Finance,
...Accounting,
...Plugin,
...Setting
],
beforeEnter: (to, from, next) => {
// redirect to sign in page if not authenticated
if (!store.state.auth.user) {
if (Vue.cookie.get('TAT') !== null) {
store.dispatch('reloadVuex')
.then(response => {
if (window.location.host === process.env.VUE_APP_DOMAIN) {
next('/account')
} else {
next()
}
}).catch(error => {
console.log(error)
next('/503')
})
} else {
next({ path: '/auth/signin', query: { r: to.fullPath } })
}
} else {
// redirect to account route if host is not tenant subdomain
if (window.location.host === process.env.VUE_APP_DOMAIN) {
next('/account')
} else {
next()
}
}
}
},
{
path: '/approval',
component: Approval
},
{
path: '/approval-all',
component: ApprovalAll
},
{
path: '/404',
component: E404
},
{
path: '/503',
component: E503
},
{
path: '*',
beforeEnter: (to, from, next) => {
next('/')
}
}
]
})