// src/router/index.js createWebHistory
import {createRouter, createWebHashHistory} from 'vue-router'
import { defineAsyncComponent } from 'vue'
const router = createRouter({
     history: createWebHashHistory(),  // hash 模式
    //history: createWebHistory(),  // history 模式
    routes: [
        {
            path: '/',
            name: 'home',
            component: defineAsyncComponent(() => import(`../views/home.vue`)),
            meta: {
                title: '实验室安全智能监测与控制系统',
            },
        },
        {
            path: '/admittanceDetail',
            name: 'admittanceDetail',
            component: defineAsyncComponent(() => import(`../views/admittanceDetail.vue`)),
            meta: {
                title: '安全准入办理统计',
            },
        },
        {
            path: '/controlDetail',
            name: 'controlDetail',
            component: defineAsyncComponent(() => import(`../views/controlDetail.vue`)),
            meta: {
                title: '分级管控',
            },
        },
        {
            path: '/dangerDetail',
            name: 'dangerDetail',
            component: defineAsyncComponent(() => import(`../views/dangerDetail.vue`)),
            meta: {
                title: '安全隐患统计',
            },
        },
        {
            path: '/illegalDetail',
            name: 'illegalDetail',
            component: defineAsyncComponent(() => import(`../views/illegalDetail.vue`)),
            meta: {
                title: '人员违规统计',
            },
        },
        {
            path: '/inspectDetail',
            name: 'inspectDetail',
            component: defineAsyncComponent(() => import(`../views/inspectDetail.vue`)),
            meta: {
                title: '安全检查',
            },
        },
        {
            path: '/inspectDetail2',
            name: 'inspectDetail2',
            component: defineAsyncComponent(() => import(`../views/inspectDetail2.vue`)),
            meta: {
                title: '安全检查',
            },
        },
        {
            path: '/labPersonDetail',
            name: 'labPersonDetail',
            component: defineAsyncComponent(() => import(`../views/labPersonDetail.vue`)),
            meta: {
                title: '进入实验室人员',
            },
        },
        {
            path: '/planDetail',
            name: 'planDetail',
            component: defineAsyncComponent(() => import(`../views/planDetail.vue`)),
            meta: {
                title: '预案执行统计',
            },
        },
        {
            path: '/riskDetail',
            name: 'riskDetail',
            component: defineAsyncComponent(() => import(`../views/riskDetail.vue`)),
            meta: {
                title: '危险源统计',
            },
        },
        {
            path: '/warningDetail',
            name: 'warningDetail',
            component: defineAsyncComponent(() => import(`../views/warningDetail.vue`)),
            meta: {
                title: '预案',
            },
        },
        {
            path: '/workInfoDetail',
            name: 'workInfoDetail',
            component: defineAsyncComponent(() => import(`../views/workInfoDetail.vue`)),
            meta: {
                title: '工作通知',
            },
        },
        {
            path: '/workPlanDetail',
            name: 'workPlanDetail',
            component: defineAsyncComponent(() => import(`../views/workPlanDetail.vue`)),
            meta: {
                title: '工作计划',
            },
        },
        {
            path: '/classifyGradeDetail',
            name: 'classifyGradeDetail',
            component: defineAsyncComponent(() => import(`../views/classifyGradeDetail.vue`)),
            meta: {
                title: '实验室分类分级',
            },
        },
        {
            path: '/*',
            redirect: '/',
        },
    ]
})
// 全局路由守卫
router.beforeEach((to, from, next)=>{
    // console.log(to, from)
    if (to.meta.title) {
        document.title = `${to.meta.title}`;
    }
    next()
})

export default router
