File was renamed from src/router/index.ts |
| | |
| | | import { createRouter, createWebHashHistory } from 'vue-router'; // createWebHashHistory, createWebHistory |
| | | import type { Router, RouteRecordRaw, RouteComponent } from 'vue-router'; |
| | | // import type { Router, RouteRecordRaw, RouteComponent } from 'vue-router'; |
| | | |
| | | import devicesRouter from './modules/devices'; |
| | | import generalRouter from './modules/general'; |
| | | import systemRouter from './modules/system'; |
| | | /* Layout */ |
| | | const Layout = ():RouteComponent => import('@/layout/index.vue'); |
| | | const Layout = () => import('@/layout/index.vue'); |
| | | |
| | | /** |
| | | * constantRoutes |
| | |
| | | * |
| | | * 注意:hidden、alwaysShow 属性配置移动到了meta中!!! |
| | | */ |
| | | export const constantRoutes:RouteRecordRaw[] = [ |
| | | export const constantRoutes = [ |
| | | { |
| | | path: '/redirect', |
| | | component: Layout, |
| | |
| | | { |
| | | path: '/', |
| | | component: Layout, |
| | | redirect: '/dashboard', |
| | | children: [ |
| | | { |
| | | path: 'dashboard', |
| | | component: () => import('@/views/dashboard/index.vue'), |
| | | name: 'Dashboard', |
| | | meta: { title: '首页', icon: 'home-hdw', affix: true } |
| | | } |
| | | ] |
| | | // redirect: '/dashboard', |
| | | redirect: '/device/lock', |
| | | // children: [ |
| | | // { |
| | | // path: 'dashboard', |
| | | // component: () => import('@/views/dashboard/index.vue'), |
| | | // name: 'Dashboard', |
| | | // meta: { title: '首页', icon: 'home-hdw', affix: true } |
| | | // } |
| | | // ] |
| | | } |
| | | ]; |
| | | |
| | |
| | | * |
| | | * 注意:hidden、alwaysShow 属性配置移动到了meta中!!! |
| | | */ |
| | | export const asyncRoutes:RouteRecordRaw[] = [ |
| | | export const asyncRoutes = [ |
| | | devicesRouter, |
| | | generalRouter, |
| | | systemRouter, |
| | |
| | | { path: '/:pathMatch(.*)*', redirect: '/404', meta: { hidden: true }} |
| | | ]; |
| | | |
| | | // console.log('asyncRoutes=', asyncRoutes, '============='); |
| | | |
| | | console.log('BASE_URL=', import.meta.env); |
| | | |
| | | const createTheRouter = ():Router => createRouter({ |
| | | const createTheRouter = () => createRouter({ |
| | | history: createWebHashHistory(import.meta.env.BASE_URL), |
| | | // 注意,如果要配置 HTML5 模式,则需要修改nginx配置,参考资料: |
| | | // https://router.vuejs.org/zh/guide/essentials/history-mode.html |
| | |
| | | routes: constantRoutes |
| | | }); |
| | | |
| | | interface RouterPro extends Router { |
| | | matcher: unknown; |
| | | } |
| | | // interface RouterPro extends Router { |
| | | // matcher: unknown; |
| | | // } |
| | | |
| | | const router = createTheRouter() as RouterPro; |
| | | const router = createTheRouter() ; |
| | | |
| | | // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465 |
| | | export function resetRouter() { |
| | | const newRouter = createTheRouter() as RouterPro; |
| | | const newRouter = createTheRouter(); |
| | | router.matcher = newRouter.matcher; // reset router |
| | | } |
| | | |