Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. const router = new Router({
  2. mode: 'history',
  3. routes: [
  4. {
  5. path: '/',
  6. name: 'landing',
  7. component: Landing,
  8. meta: {
  9. guest: true
  10. }
  11. },
  12. {
  13. path: '/verify-email',
  14. name: 'verify-email',
  15. component: VerifyEmail,
  16. meta: {
  17. guest: true
  18. }
  19. },
  20. {
  21. path: '/auth/login',
  22. name: 'login',
  23. component: Login,
  24. meta: {
  25. guest: true
  26. }
  27. },
  28. {
  29. path: '/auth/register',
  30. name: 'register',
  31. component: Register,
  32. meta: {
  33. guest: true
  34. }
  35. },
  36. {
  37. path: '/dashboard',
  38. redirect: { name: 'landing' },
  39. component: App,
  40. meta: {
  41. requiresAuth: true
  42. },
  43. children: [
  44. {
  45. path: '',
  46. component: Dashboard,
  47. children: [
  48. {
  49. path: '/home',
  50. name: 'home',
  51. component: Home,
  52. },
  53. {
  54. path: '/downloads',
  55. name: 'downloads',
  56. component: Downloads,
  57. },
  58. {
  59. path: '/reports',
  60. name: 'reports',
  61. component: Reports,
  62. },
  63. {
  64. path: 'charts',
  65. component: Charts,
  66. children: [
  67. {
  68. path: '',
  69. name: 'charts',
  70. component: ChartsIndex
  71. },
  72. {
  73. path: 'general',
  74. name: 'general-reports',
  75. component: GeneralReports
  76. },
  77. {
  78. path: 'activity',
  79. name: 'activity-reports',
  80. component: ActivityReports
  81. },
  82. {
  83. path: 'forms',
  84. name: 'forms-reports',
  85. component: FormsReports
  86. }
  87. ]
  88. },
  89. {
  90. path: 'instances',
  91. name: 'instances',
  92. component: Instances,
  93. },
  94. {
  95. path: 'instances/:id',
  96. name: 'instance',
  97. component: Instance
  98. },
  99. {
  100. path: 'leaderboards',
  101. name: 'leaderboards',
  102. component: Leaderboards,
  103. },
  104. {
  105. path: 'leaderboards/leader/:id',
  106. name: 'leader',
  107. component: Leader
  108. },
  109. {
  110. path: 'leaderboards/leader/:id/map',
  111. name: 'leader-map-activity',
  112. component: LeaderMapActivity
  113. },
  114. {
  115. path: 'maps',
  116. name: 'maps',
  117. component: Maps,
  118. },
  119. {
  120. path: 'organization',
  121. name: 'organization',
  122. component: ManageOrganization,
  123. children: [
  124. {
  125. path: 'tiers',
  126. name: 'tiers',
  127. component: Tiers,
  128. },
  129. {
  130. path: 'territories',
  131. name: 'territories',
  132. component: Territories,
  133. },
  134. {
  135. path: 'zones',
  136. name: 'zones',
  137. component: Zones,
  138. },
  139. {
  140. path: ':linkName/:zone_id',
  141. name: 'zone',
  142. component: Zone
  143. },
  144. {
  145. path: 'areas',
  146. name: 'areas',
  147. component: Areas,
  148. },
  149. {
  150. path: ':linkName/:area_id',
  151. name: 'area',
  152. component: Area
  153. },
  154. {
  155. path: 'countries',
  156. name: 'countries',
  157. component: Countries,
  158. },
  159. {
  160. path: ':linkName/:country_id',
  161. name: 'country',
  162. props: true,
  163. component: Country
  164. }
  165. ],
  166. },
  167. {
  168. path: 'users',
  169. name: 'users',
  170. component: ManageUsers,
  171. children: [
  172. {
  173. path: 'tiers',
  174. name: 'users-tiers',
  175. component: UsersTiers
  176. },
  177. {
  178. path: 'roletypes',
  179. name: 'role-types',
  180. component: RoleTypes
  181. },
  182. {
  183. path: ':linkName/:roleType_id',
  184. name: 'role-type',
  185. component: RoleType
  186. },
  187. {
  188. path: 'list',
  189. name: 'users-list',
  190. component: Users
  191. },
  192. {
  193. path: ':linkName/:user_id',
  194. name: 'user',
  195. component: User
  196. }
  197. ]
  198. },
  199. {
  200. path: 'entities',
  201. name: 'entities',
  202. component: ManageEntities,
  203. children: [
  204. {
  205. path: 'tiers',
  206. name: 'entity-tiers',
  207. component: EntityTiers
  208. },
  209. {
  210. path: 'list',
  211. name: 'entities-list',
  212. component: EntitiesList,
  213. },
  214. {
  215. path: 'new',
  216. name: 'entity-new',
  217. component: NewEntity,
  218. },
  219. {
  220. path: 'entity/:entity_id',
  221. name: 'entity',
  222. component: Entity,
  223. },
  224. {
  225. path: 'actions',
  226. name: 'actions',
  227. component: Actions,
  228. },
  229. {
  230. path: 'action/:action_id',
  231. name: 'action',
  232. component: Action
  233. },
  234. // {
  235. // path: 'action/new',
  236. // name: 'action-new',
  237. // component: NewAction,
  238. // },
  239. {
  240. path: 'new_action',
  241. name: 'new-action',
  242. component: NewAction,
  243. },
  244. ],
  245. },
  246. ],
  247. },
  248. ],
  249. },
  250. {
  251. path: '/admin',
  252. component: AdminLanding,
  253. meta: {
  254. guest: true
  255. }
  256. },
  257. {
  258. path: '*',
  259. component: NotFound,
  260. meta: {
  261. guest: true
  262. }
  263. },
  264. ],
  265. });
  266.  
  267. router.beforeEach((to, from, next) => {
  268. if (to.matched.some(record => record.meta.requiresAuth)) {
  269. if (localStorage.getItem('token') == null) {
  270. next({
  271. name: 'login',
  272. params: { nextUrl: to.fullPath }
  273. });
  274. } else {
  275. const user = JSON.parse(localStorage.getItem('user'));
  276. if (to.matched.some(record => record.meta.is_admin)) {
  277. if (user.role === 'saas' || user.role === 'cs') {
  278. next();
  279. } else {
  280. next({
  281. name: 'home'
  282. });
  283. }
  284. } else {
  285. next();
  286. }
  287. }
  288. } else if (to.matched.some(record => record.meta.guest)) {
  289. if (localStorage.getItem('token') == null) {
  290. next();
  291. } else {
  292. next({
  293. name: 'home'
  294. });
  295. }
  296. } else {
  297. next();
  298. }
  299. });
  300.  
  301. export default router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement