2021-12-30 17:25:51 +08:00
|
|
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
|
|
import type { RouteRecordRaw } from 'vue-router'
|
|
|
|
import type { App } from 'vue'
|
|
|
|
// import { getParentLayout } from './helper'
|
2022-01-09 10:57:50 +08:00
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
/* Layout */
|
|
|
|
const Layout = () => import('@/layout/Layout.vue')
|
2021-12-30 17:25:51 +08:00
|
|
|
|
|
|
|
export const constantRouterMap: AppRouteRecordRaw[] = [
|
2022-01-09 10:57:50 +08:00
|
|
|
{
|
|
|
|
path: '/redirect',
|
|
|
|
component: Layout,
|
|
|
|
name: 'Redirect',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: '/redirect/:path*',
|
|
|
|
name: 'Redirect',
|
|
|
|
component: () => import('@/views/Redirect/Redirect.vue'),
|
|
|
|
meta: {}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
meta: {
|
|
|
|
hidden: true
|
|
|
|
}
|
|
|
|
},
|
2021-12-30 17:25:51 +08:00
|
|
|
{
|
|
|
|
path: '/login',
|
|
|
|
component: () => import('@/views/Login/Login.vue'),
|
|
|
|
name: 'Login',
|
|
|
|
meta: {
|
|
|
|
hidden: true,
|
2022-01-09 10:57:50 +08:00
|
|
|
title: t('router.login'),
|
2021-12-30 17:25:51 +08:00
|
|
|
noTagsView: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
history: createWebHashHistory(),
|
2022-01-03 09:41:34 +08:00
|
|
|
strict: true,
|
2021-12-30 17:25:51 +08:00
|
|
|
routes: constantRouterMap as RouteRecordRaw[],
|
|
|
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
|
|
})
|
|
|
|
|
|
|
|
export function resetRouter(): void {
|
|
|
|
const resetWhiteNameList = ['RedirectRoot', 'Redirect', 'Login', 'Root', 'Dashboard', 'Page404']
|
|
|
|
router.getRoutes().forEach((route) => {
|
|
|
|
const { name } = route
|
|
|
|
if (name && !resetWhiteNameList.includes(name as string)) {
|
|
|
|
router.hasRoute(name) && router.removeRoute(name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setupRouter(app: App<Element>) {
|
|
|
|
app.use(router)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default router
|