gohttpdUi/src/router/index.ts

62 lines
1.5 KiB
TypeScript
Raw Normal View History

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'
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[] = [
{
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,
title: t('router.login'),
2021-12-30 17:25:51 +08:00
noTagsView: true
}
}
]
const router = createRouter({
history: createWebHashHistory(),
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