Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const router = new Router({
- mode: 'history',
- routes: [
- {
- path: '/',
- name: 'landing',
- component: Landing,
- meta: {
- guest: true
- }
- },
- {
- path: '/verify-email',
- name: 'verify-email',
- component: VerifyEmail,
- meta: {
- guest: true
- }
- },
- {
- path: '/auth/login',
- name: 'login',
- component: Login,
- meta: {
- guest: true
- }
- },
- {
- path: '/auth/register',
- name: 'register',
- component: Register,
- meta: {
- guest: true
- }
- },
- {
- path: '/dashboard',
- redirect: { name: 'landing' },
- component: App,
- meta: {
- requiresAuth: true
- },
- children: [
- {
- path: '',
- component: Dashboard,
- children: [
- {
- path: '/home',
- name: 'home',
- component: Home,
- },
- {
- path: '/downloads',
- name: 'downloads',
- component: Downloads,
- },
- {
- path: '/reports',
- name: 'reports',
- component: Reports,
- },
- {
- path: 'charts',
- component: Charts,
- children: [
- {
- path: '',
- name: 'charts',
- component: ChartsIndex
- },
- {
- path: 'general',
- name: 'general-reports',
- component: GeneralReports
- },
- {
- path: 'activity',
- name: 'activity-reports',
- component: ActivityReports
- },
- {
- path: 'forms',
- name: 'forms-reports',
- component: FormsReports
- }
- ]
- },
- {
- path: 'instances',
- name: 'instances',
- component: Instances,
- },
- {
- path: 'instances/:id',
- name: 'instance',
- component: Instance
- },
- {
- path: 'leaderboards',
- name: 'leaderboards',
- component: Leaderboards,
- },
- {
- path: 'leaderboards/leader/:id',
- name: 'leader',
- component: Leader
- },
- {
- path: 'leaderboards/leader/:id/map',
- name: 'leader-map-activity',
- component: LeaderMapActivity
- },
- {
- path: 'maps',
- name: 'maps',
- component: Maps,
- },
- {
- path: 'organization',
- name: 'organization',
- component: ManageOrganization,
- children: [
- {
- path: 'tiers',
- name: 'tiers',
- component: Tiers,
- },
- {
- path: 'territories',
- name: 'territories',
- component: Territories,
- },
- {
- path: 'zones',
- name: 'zones',
- component: Zones,
- },
- {
- path: ':linkName/:zone_id',
- name: 'zone',
- component: Zone
- },
- {
- path: 'areas',
- name: 'areas',
- component: Areas,
- },
- {
- path: ':linkName/:area_id',
- name: 'area',
- component: Area
- },
- {
- path: 'countries',
- name: 'countries',
- component: Countries,
- },
- {
- path: ':linkName/:country_id',
- name: 'country',
- props: true,
- component: Country
- }
- ],
- },
- {
- path: 'users',
- name: 'users',
- component: ManageUsers,
- children: [
- {
- path: 'tiers',
- name: 'users-tiers',
- component: UsersTiers
- },
- {
- path: 'roletypes',
- name: 'role-types',
- component: RoleTypes
- },
- {
- path: ':linkName/:roleType_id',
- name: 'role-type',
- component: RoleType
- },
- {
- path: 'list',
- name: 'users-list',
- component: Users
- },
- {
- path: ':linkName/:user_id',
- name: 'user',
- component: User
- }
- ]
- },
- {
- path: 'entities',
- name: 'entities',
- component: ManageEntities,
- children: [
- {
- path: 'tiers',
- name: 'entity-tiers',
- component: EntityTiers
- },
- {
- path: 'list',
- name: 'entities-list',
- component: EntitiesList,
- },
- {
- path: 'new',
- name: 'entity-new',
- component: NewEntity,
- },
- {
- path: 'entity/:entity_id',
- name: 'entity',
- component: Entity,
- },
- {
- path: 'actions',
- name: 'actions',
- component: Actions,
- },
- {
- path: 'action/:action_id',
- name: 'action',
- component: Action
- },
- // {
- // path: 'action/new',
- // name: 'action-new',
- // component: NewAction,
- // },
- {
- path: 'new_action',
- name: 'new-action',
- component: NewAction,
- },
- ],
- },
- ],
- },
- ],
- },
- {
- path: '/admin',
- component: AdminLanding,
- meta: {
- guest: true
- }
- },
- {
- path: '*',
- component: NotFound,
- meta: {
- guest: true
- }
- },
- ],
- });
- router.beforeEach((to, from, next) => {
- if (to.matched.some(record => record.meta.requiresAuth)) {
- if (localStorage.getItem('token') == null) {
- next({
- name: 'login',
- params: { nextUrl: to.fullPath }
- });
- } else {
- const user = JSON.parse(localStorage.getItem('user'));
- if (to.matched.some(record => record.meta.is_admin)) {
- if (user.role === 'saas' || user.role === 'cs') {
- next();
- } else {
- next({
- name: 'home'
- });
- }
- } else {
- next();
- }
- }
- } else if (to.matched.some(record => record.meta.guest)) {
- if (localStorage.getItem('token') == null) {
- next();
- } else {
- next({
- name: 'home'
- });
- }
- } else {
- next();
- }
- });
- export default router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement