123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567 |
- import { createRouter, createWebHashHistory } from 'vue-router'
- import type { RouteRecordRaw } from 'vue-router'
- import type { App } from 'vue'
- import { Layout, getParentLayout } from '@/utils/routerHelper'
- import { useI18n } from '@/hooks/web/useI18n'
- const { t } = useI18n()
- export const constantRouterMap: AppRouteRecordRaw[] = [
- {
- path: '/',
- component: Layout,
- redirect: '/dashboard/analysis',
- name: 'Root',
- meta: {
- hidden: true
- }
- },
- {
- path: '/redirect',
- component: Layout,
- name: 'Redirect',
- children: [
- {
- path: '/redirect/:path(.*)',
- name: 'Redirect',
- component: () => import('@/views/Redirect/Redirect.vue'),
- meta: {}
- }
- ],
- meta: {
- hidden: true,
- noTagsView: true
- }
- },
- {
- path: '/login',
- component: () => import('@/views/Login/Login.vue'),
- name: 'Login',
- meta: {
- hidden: true,
- title: t('router.login'),
- noTagsView: true
- }
- },
- {
- path: '/404',
- component: () => import('@/views/Error/404.vue'),
- name: 'NoFind',
- meta: {
- hidden: true,
- title: '404',
- noTagsView: true
- }
- }
- ]
- export const asyncRouterMap: AppRouteRecordRaw[] = [
- {
- path: '/dashboard',
- component: Layout,
- redirect: '/dashboard/analysis',
- name: 'Dashboard',
- meta: {
- title: t('router.dashboard'),
- icon: 'ant-design:dashboard-filled',
- alwaysShow: true
- },
- children: [
- {
- path: 'analysis',
- component: () => import('@/views/Dashboard/Analysis.vue'),
- name: 'Analysis',
- meta: {
- title: t('router.analysis'),
- noCache: true,
- affix: true
- }
- },
- {
- path: 'workplace',
- component: () => import('@/views/Dashboard/Workplace.vue'),
- name: 'Workplace',
- meta: {
- title: t('router.workplace'),
- noCache: true
- }
- }
- ]
- },
- {
- path: '/external-link',
- component: Layout,
- meta: {},
- name: 'ExternalLink',
- children: [
- {
- path: 'https://element-plus-admin-doc.cn/',
- name: 'DocumentLink',
- meta: {
- title: t('router.document'),
- icon: 'clarity:document-solid'
- }
- }
- ]
- },
- {
- path: '/guide',
- component: Layout,
- name: 'Guide',
- meta: {},
- children: [
- {
- path: 'index',
- component: () => import('@/views/Guide/Guide.vue'),
- name: 'GuideDemo',
- meta: {
- title: t('router.guide'),
- icon: 'cib:telegram-plane'
- }
- }
- ]
- },
- {
- path: '/components',
- component: Layout,
- redirect: '/components/icon',
- name: 'ComponentsDemo',
- meta: {
- title: t('router.component'),
- icon: 'bx:bxs-component',
- alwaysShow: true
- },
- children: [
- {
- path: 'form',
- component: getParentLayout(),
- name: 'Form',
- meta: {
- title: t('router.form'),
- alwaysShow: true
- },
- children: [
- {
- path: 'default-form',
- component: () => import('@/views/Components/Form/DefaultForm.vue'),
- name: 'DefaultForm',
- meta: {
- title: t('router.defaultForm')
- }
- },
- {
- path: 'use-form',
- component: () => import('@/views/Components/Form/UseFormDemo.vue'),
- name: 'UseForm',
- meta: {
- title: 'UseForm'
- }
- },
- {
- path: 'ref-form',
- component: () => import('@/views/Components/Form/RefForm.vue'),
- name: 'RefForm',
- meta: {
- title: 'RefForm'
- }
- }
- ]
- },
- {
- path: 'table',
- component: getParentLayout(),
- name: 'TableDemo',
- meta: {
- title: t('router.table'),
- alwaysShow: true
- },
- children: [
- {
- path: 'default-table',
- component: () => import('@/views/Components/Table/DefaultTable.vue'),
- name: 'DefaultTable',
- meta: {
- title: t('router.defaultTable')
- }
- },
- {
- path: 'use-table',
- component: () => import('@/views/Components/Table/UseTableDemo.vue'),
- name: 'UseTable',
- meta: {
- title: 'UseTable'
- }
- },
- {
- path: 'ref-table',
- component: () => import('@/views/Components/Table/RefTable.vue'),
- name: 'RefTable',
- meta: {
- title: 'RefTable'
- }
- }
- ]
- },
- {
- path: 'editor-demo',
- component: getParentLayout(),
- name: 'EditorDemo',
- meta: {
- title: t('router.editor'),
- alwaysShow: true
- },
- children: [
- {
- path: 'editor',
- component: () => import('@/views/Components/Editor/Editor.vue'),
- name: 'Editor',
- meta: {
- title: t('router.richText')
- }
- }
- ]
- },
- {
- path: 'search',
- component: () => import('@/views/Components/Search.vue'),
- name: 'Search',
- meta: {
- title: t('router.search')
- }
- },
- {
- path: 'descriptions',
- component: () => import('@/views/Components/Descriptions.vue'),
- name: 'Descriptions',
- meta: {
- title: t('router.descriptions')
- }
- },
- {
- path: 'image-viewer',
- component: () => import('@/views/Components/ImageViewer.vue'),
- name: 'ImageViewer',
- meta: {
- title: t('router.imageViewer')
- }
- },
- {
- path: 'dialog',
- component: () => import('@/views/Components/Dialog.vue'),
- name: 'Dialog',
- meta: {
- title: t('router.dialog')
- }
- },
- {
- path: 'icon',
- component: () => import('@/views/Components/Icon.vue'),
- name: 'Icon',
- meta: {
- title: t('router.icon')
- }
- },
- {
- path: 'echart',
- component: () => import('@/views/Components/Echart.vue'),
- name: 'Echart',
- meta: {
- title: t('router.echart')
- }
- },
- {
- path: 'count-to',
- component: () => import('@/views/Components/CountTo.vue'),
- name: 'CountTo',
- meta: {
- title: t('router.countTo')
- }
- },
- {
- path: 'qrcode',
- component: () => import('@/views/Components/Qrcode.vue'),
- name: 'Qrcode',
- meta: {
- title: t('router.qrcode')
- }
- },
- {
- path: 'highlight',
- component: () => import('@/views/Components/Highlight.vue'),
- name: 'Highlight',
- meta: {
- title: t('router.highlight')
- }
- },
- {
- path: 'infotip',
- component: () => import('@/views/Components/Infotip.vue'),
- name: 'Infotip',
- meta: {
- title: t('router.infotip')
- }
- },
- {
- path: 'input-password',
- component: () => import('@/views/Components/InputPassword.vue'),
- name: 'InputPassword',
- meta: {
- title: t('router.inputPassword')
- }
- },
- {
- path: 'sticky',
- component: () => import('@/views/Components/Sticky.vue'),
- name: 'Sticky',
- meta: {
- title: t('router.sticky')
- }
- }
- ]
- },
- {
- path: '/hooks',
- component: Layout,
- redirect: '/hooks/useWatermark',
- name: 'Hooks',
- meta: {
- title: 'hooks',
- icon: 'ic:outline-webhook',
- alwaysShow: true
- },
- children: [
- {
- path: 'useWatermark',
- component: () => import('@/views/hooks/useWatermark.vue'),
- name: 'UseWatermark',
- meta: {
- title: 'useWatermark'
- }
- },
- {
- path: 'useCrudSchemas',
- component: () => import('@/views/hooks/useCrudSchemas.vue'),
- name: 'UseCrudSchemas',
- meta: {
- title: 'useCrudSchemas'
- }
- }
- ]
- },
- {
- path: '/level',
- component: Layout,
- redirect: '/level/menu1/menu1-1/menu1-1-1',
- name: 'Level',
- meta: {
- title: t('router.level'),
- icon: 'carbon:skill-level-advanced'
- },
- children: [
- {
- path: 'menu1',
- name: 'Menu1',
- component: getParentLayout(),
- redirect: '/level/menu1/menu1-1/menu1-1-1',
- meta: {
- title: t('router.menu1')
- },
- children: [
- {
- path: 'menu1-1',
- name: 'Menu11',
- component: getParentLayout(),
- redirect: '/level/menu1/menu1-1/menu1-1-1',
- meta: {
- title: t('router.menu11'),
- alwaysShow: true
- },
- children: [
- {
- path: 'menu1-1-1',
- name: 'Menu111',
- component: () => import('@/views/Level/Menu111.vue'),
- meta: {
- title: t('router.menu111')
- }
- }
- ]
- },
- {
- path: 'menu1-2',
- name: 'Menu12',
- component: () => import('@/views/Level/Menu12.vue'),
- meta: {
- title: t('router.menu12')
- }
- }
- ]
- },
- {
- path: 'menu2',
- name: 'Menu2',
- component: () => import('@/views/Level/Menu2.vue'),
- meta: {
- title: t('router.menu2')
- }
- }
- ]
- },
- {
- path: '/example',
- component: Layout,
- redirect: '/example/example-dialog',
- name: 'Example',
- meta: {
- title: t('router.example'),
- icon: 'ep:management',
- alwaysShow: true
- },
- children: [
- {
- path: 'example-dialog',
- component: () => import('@/views/Example/Dialog/ExampleDialog.vue'),
- name: 'ExampleDialog',
- meta: {
- title: t('router.exampleDialog')
- }
- },
- {
- path: 'example-page',
- component: () => import('@/views/Example/Page/ExamplePage.vue'),
- name: 'ExamplePage',
- meta: {
- title: t('router.examplePage')
- }
- },
- {
- path: 'example-add',
- component: () => import('@/views/Example/Page/ExampleAdd.vue'),
- name: 'ExampleAdd',
- meta: {
- title: t('router.exampleAdd'),
- noTagsView: true,
- noCache: true,
- hidden: true,
- canTo: true,
- activeMenu: '/example/example-page'
- }
- },
- {
- path: 'example-edit',
- component: () => import('@/views/Example/Page/ExampleEdit.vue'),
- name: 'ExampleEdit',
- meta: {
- title: t('router.exampleEdit'),
- noTagsView: true,
- noCache: true,
- hidden: true,
- canTo: true,
- activeMenu: '/example/example-page'
- }
- },
- {
- path: 'example-detail',
- component: () => import('@/views/Example/Page/ExampleDetail.vue'),
- name: 'ExampleDetail',
- meta: {
- title: t('router.exampleDetail'),
- noTagsView: true,
- noCache: true,
- hidden: true,
- canTo: true,
- activeMenu: '/example/example-page'
- }
- }
- ]
- },
- {
- path: '/error',
- component: Layout,
- redirect: '/error/404',
- name: 'Error',
- meta: {
- title: t('router.errorPage'),
- icon: 'ci:error',
- alwaysShow: true
- },
- children: [
- {
- path: '404-demo',
- component: () => import('@/views/Error/404.vue'),
- name: '404Demo',
- meta: {
- title: '404'
- }
- },
- {
- path: '403-demo',
- component: () => import('@/views/Error/403.vue'),
- name: '403Demo',
- meta: {
- title: '403'
- }
- },
- {
- path: '500-demo',
- component: () => import('@/views/Error/500.vue'),
- name: '500Demo',
- meta: {
- title: '500'
- }
- }
- ]
- }
- // {
- // path: '/authorization',
- // component: Layout,
- // redirect: '/authorization/user',
- // name: 'Authorization',
- // meta: {
- // title: t('router.authorization'),
- // icon: 'eos-icons:role-binding',
- // alwaysShow: true
- // },
- // children: [
- // {
- // path: 'user',
- // component: () => import('@/views/Authorization/User.vue'),
- // name: 'User',
- // meta: {
- // title: t('router.user')
- // }
- // },
- // {
- // path: 'role',
- // component: () => import('@/views/Authorization/Role.vue'),
- // name: 'Role',
- // meta: {
- // title: t('router.role')
- // }
- // }
- // ]
- // }
- ]
- const router = createRouter({
- history: createWebHashHistory(),
- strict: true,
- routes: constantRouterMap as RouteRecordRaw[],
- scrollBehavior: () => ({ left: 0, top: 0 })
- })
- export const resetRouter = (): void => {
- const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
- router.getRoutes().forEach((route) => {
- const { name } = route
- if (name && !resetWhiteNameList.includes(name as string)) {
- router.hasRoute(name) && router.removeRoute(name)
- }
- })
- }
- export const setupRouter = (app: App<Element>) => {
- app.use(router)
- }
- export default router
|