// 配置路由相关的信息
import VueRouter from 'vue-router'
import Vue from 'vue'

import Home from '../pages/index/index'
import gasCard from '../pages/gasCard/gasCard'
import eleFireCard from '../pages/eleFireCard/eleFireCard'
import eleFireData from '../pages/eleFireData/eleFireData'
import inspectRecord from '../pages/inspectRecord/inspectRecord'
import recordTime from '../pages/recordTime/recordTime'
import pagination from '../pages/test/pagination'





// 1.通过Vue.use(插件), 安装插件
Vue.use(VueRouter)

// 2.创建VueRouter对象
const routes = [{
        path: '',
        // redirect重定向
        redirect: '/index'
    },
    {
        path: '/index',
        component: Home,
        meta: { title: '站点信息页' },
    }, {
        path: '/gasCard',
        component: gasCard,
        meta: { title: '可燃气体' },
    }, {
        path: '/eleFireCard',
        component: eleFireCard,
        meta: { title: '电气火灾卡片页' },
    }, {
        path: '/eleFireData',
        component: eleFireData,
        meta: { title: '电气火灾数据展示' },
    }, {
        path: '/inspectRecord',
        component: inspectRecord,
        meta: { title: '在线巡检记录' },
    }, {
        path: '/recordTime',
        name: 'recordTime',
        component: recordTime,
        meta: { title: '在线自动巡检记录' },
    }, {
        path: '/pagination',
        name: 'pagination',
        component: pagination,
        meta: { title: '分页测试' },
    }
]
const router = new VueRouter({
    // 配置路由和组件之间的应用关系
    routes,
    // mode: 'history',
    linkActiveClass: 'active'
})

// const VueRouterPush = router.prototype.push

// router.prototype.push = function push(to) {

//     return VueRouterPush.call(this, to).catch(err => err)

// }




// 3.将router对象传入到Vue实例
router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})





export default router