mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-09 20:57:17 +08:00
103 lines
2.5 KiB
TypeScript
103 lines
2.5 KiB
TypeScript
import { type RouteRecordRaw, createRouter, createWebHashHistory } from 'vue-router'
|
|
import { useRouteStore } from '@/stores'
|
|
|
|
/** 默认布局 */
|
|
const Layout = () => import('@/layout/index.vue')
|
|
|
|
/** 静态路由 */
|
|
export const constantRoutes: RouteRecordRaw[] = [
|
|
{
|
|
path: '/redirect',
|
|
component: Layout,
|
|
meta: { hidden: true },
|
|
children: [
|
|
{
|
|
path: '/redirect/:path(.*)',
|
|
component: () => import('@/views/default/redirect/index.vue')
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/login',
|
|
component: () => import('@/views/login/index.vue'),
|
|
meta: { hidden: true }
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
component: () => import('@/views/default/error/404.vue'),
|
|
meta: { hidden: true }
|
|
},
|
|
{
|
|
path: '/403',
|
|
component: () => import('@/views/default/error/403.vue'),
|
|
meta: { hidden: true }
|
|
},
|
|
{
|
|
path: '/',
|
|
name: 'Home',
|
|
component: Layout,
|
|
redirect: '/home',
|
|
meta: { hidden: false },
|
|
children: [
|
|
{
|
|
path: '/home',
|
|
name: 'Home',
|
|
component: () => import('@/views/home/index.vue'),
|
|
meta: { title: '首页', icon: 'dashboard', affix: true, hidden: false }
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/social/callback',
|
|
component: () => import('@/views/login/social/index.vue'),
|
|
meta: { hidden: true }
|
|
},
|
|
{
|
|
path: '/setting',
|
|
name: 'Setting',
|
|
component: Layout,
|
|
meta: { hidden: true },
|
|
children: [
|
|
{
|
|
path: '/setting/profile',
|
|
name: 'SettingProfile',
|
|
component: () => import('@/views/setting/profile/index.vue'),
|
|
meta: { title: '个人中心', showInTabs: false }
|
|
},
|
|
{
|
|
path: '/setting/message',
|
|
name: 'SettingMessage',
|
|
component: () => import('@/views/setting/message/index.vue'),
|
|
meta: { title: '消息中心', showInTabs: false }
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHashHistory(import.meta.env.BASE_URL),
|
|
routes: constantRoutes,
|
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
})
|
|
|
|
/**
|
|
* @description 重置路由
|
|
* @description 注意:所有动态路由路由必须带有 name 属性,否则可能会不能完全重置干净
|
|
*/
|
|
export function resetRouter() {
|
|
try {
|
|
const routeStore = useRouteStore()
|
|
routeStore.asyncRoutes.forEach((route) => {
|
|
const { name } = route
|
|
if (name) {
|
|
router.hasRoute(name) && router.removeRoute(name)
|
|
}
|
|
})
|
|
} catch (error) {
|
|
// 强制刷新浏览器也行,只是交互体验不是很好
|
|
window.location.reload()
|
|
}
|
|
}
|
|
|
|
export default router
|