index.ts 4.0 KB
Newer Older
1
import Router from 'vue-router';
2
import { Environment } from '@ibiz-template/core';
3 4 5 6 7
import { AuthGuard } from '../guard';
import RouterShell from '@/components/router-shell/router-shell';
import appRedirectView from '@/views/app-redirect-view/app-redirect-view';
import todoRedirect from '@/views/todo-redirect/todo-redirect';

8 9 10 11 12 13
const placeholder = Environment.routePlaceholder;
// 参数正则,占位符或者以等号相隔的参数键值对
const paramReg = `[^/]+=[^/]+|${placeholder}`;
// 视图正则,非=/的字符串
const viewReg = `[^=/]+`;

14 15 16 17
const router = new Router({
  routes: [
    {
      path: '/',
18
      redirect: `/${placeholder}/index/${placeholder}`,
19 20 21 22 23 24 25 26
    },
    {
      path: '/login',
      name: 'loginView',
      component: () => import('../views/login-view/login-view'),
    },
    {
      path: '/404',
27
      name: '404View1',
28 29
      component: () => import('../views/404-view/404-view'),
    },
30 31 32 33 34
    {
      path: '/403',
      name: '403View1',
      component: () => import('../views/403-view/403-view'),
    },
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
    {
      path: '/appredirectview',
      name: 'appRedirectView',
      beforeEnter: async (_to, _from, next) => {
        const authority = await AuthGuard();
        if (authority) {
          next();
        } else {
          next(false);
        }
      },
      component: appRedirectView,
    },
    {
      path: '/todoredirect',
      name: 'todoRedirect',
      beforeEnter: async (_to, _from, next) => {
        const authority = await AuthGuard();
        if (authority) {
          next();
        } else {
          next(false);
        }
      },
      component: todoRedirect,
    },
    {
62
      path: `/:appContext(${paramReg})/:view1(${viewReg})/:params1(${paramReg})`,
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
      props: {
        level: 1,
      },
      beforeEnter: async (_to, _from, next) => {
        const authority = await AuthGuard();
        if (authority) {
          next();
        } else {
          next(false);
        }
      },
      component: RouterShell,
      children: [
        {
          path: '404',
78
          name: '404View2',
79 80
          component: () => import('../views/404-view/404-view'),
        },
81 82 83 84 85
        {
          path: '403',
          name: '403View2',
          component: () => import('../views/403-view/403-view'),
        },
86
        {
87
          path: `:view2(${viewReg})/:params2(${paramReg})`,
88 89 90 91 92 93
          props: {
            level: 2,
          },
          component: RouterShell,
          children: [
            {
94 95 96 97
              path: '404',
              name: '404View3',
              component: () => import('../views/404-view/404-view'),
            },
98 99 100 101 102
            {
              path: '403',
              name: '403View3',
              component: () => import('../views/403-view/403-view'),
            },
103 104
            {
              path: `:view3(${viewReg})/:params3(${paramReg})`,
105 106 107 108
              props: {
                level: 3,
              },
              component: RouterShell,
109 110 111 112 113 114
              children: [
                {
                  path: '404',
                  name: '404View4',
                  component: () => import('../views/404-view/404-view'),
                },
115 116 117 118 119
                {
                  path: '403',
                  name: '403View4',
                  component: () => import('../views/403-view/403-view'),
                },
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
                {
                  path: `:view4(${viewReg})/:params4(${paramReg})`,
                  props: {
                    level: 4,
                  },
                  component: RouterShell,
                },
                {
                  path: '*',
                  redirect: { name: '404View4' },
                },
              ],
            },
            {
              path: '*',
              redirect: { name: '404View3' },
136 137 138
            },
          ],
        },
139 140 141 142
        {
          path: '*',
          redirect: { name: '404View2' },
        },
143 144 145
      ],
    },
    {
146 147
      path: '/*',
      redirect: { name: '404View1' },
148 149 150 151 152
    },
  ],
});

export default router;