import { createRouter, createWebHashHistory } from 'vue-router'; // createWebHashHistory, createWebHistory
|
// import type { Router, RouteRecordRaw, RouteComponent } from 'vue-router';
|
|
// import generalRouter from './modules/general';
|
import systemRouter from './modules/system';
|
import datasRouter from './modules/datas';
|
import alarmRouter from './modules/alarm';
|
import statisticsRouter from './modules/statistics';
|
import dcPowerStatus from "@/router/modules/dcPowerStatus.js";
|
/* Layout */
|
const Layout = () => import('@/layout/index.vue');
|
|
/**
|
* constantRoutes
|
* a base page that does not have permission requirements
|
* all roles can be accessed
|
*
|
* 注意:hidden、alwaysShow 属性配置移动到了meta中!!!
|
*/
|
export const constantRoutes = [
|
{
|
path: '/redirect',
|
component: Layout,
|
meta: { hidden: true },
|
children: [
|
{
|
path: '/redirect/:path(.*)',
|
component: () => import('@/views/redirect/index.vue')
|
}
|
]
|
},
|
{
|
path: '/login',
|
component: () => import('@/views/login/index.vue'),
|
meta: { hidden: true }
|
},
|
{
|
path: '/auth-redirect',
|
component: () => import('@/views/login/auth-redirect.vue'),
|
meta: { hidden: true }
|
},
|
{
|
path: '/404',
|
component: () => import('@/views/error-page/404.vue'),
|
meta: { hidden: true }
|
},
|
{
|
path: '/401',
|
component: () => import('@/views/error-page/401.vue'),
|
meta: { hidden: true }
|
},
|
// {
|
// path: '/test',
|
// component: () => import('@/views/test.vue'),
|
// meta: { hidden: true }
|
// },
|
{
|
path: '/',
|
component: Layout,
|
redirect: '/dashboard',
|
// redirect: '/device/lock',
|
children: [
|
{
|
path: 'dashboard',
|
component: () => import('@/views/dashboard/index.vue'),
|
name: 'Dashboard',
|
meta: { title: '首页', icon: 'home-hdw', affix: true }
|
}
|
]
|
}
|
];
|
|
/**
|
* asyncRoutes
|
* the routes that need to be dynamically loaded based on user roles
|
*
|
* 注意:hidden、alwaysShow 属性配置移动到了meta中!!!
|
*/
|
export const asyncRoutes = [
|
// devicesRouter,
|
// generalRouter,
|
systemRouter,
|
datasRouter,
|
alarmRouter,
|
statisticsRouter,
|
dcPowerStatus,
|
// 404 page must be placed at the end !!!
|
{ path: '/:pathMatch(.*)*', redirect: '/404', meta: { hidden: true }}
|
];
|
|
// console.log('asyncRoutes=', asyncRoutes, '=============');
|
|
console.log('BASE_URL=', import.meta.env);
|
|
const createTheRouter = () => createRouter({
|
history: createWebHashHistory(import.meta.env.BASE_URL),
|
// 注意,如果要配置 HTML5 模式,则需要修改nginx配置,参考资料:
|
// https://router.vuejs.org/zh/guide/essentials/history-mode.html
|
// history: createWebHistory(import.meta.env.BASE_URL),
|
scrollBehavior: () => ({ top: 0 }),
|
routes: constantRoutes
|
});
|
|
// interface RouterPro extends Router {
|
// matcher: unknown;
|
// }
|
|
const router = createTheRouter() ;
|
|
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
|
export function resetRouter() {
|
const newRouter = createTheRouter();
|
router.matcher = newRouter.matcher; // reset router
|
}
|
|
export default router;
|