import { createRouter, createWebHistory } from 'vue-router'

const routes= [
    {
        path: '/',
        name: 'Homepage',
        component: ()=>import('./components/Homepage.vue'),
        meta: { title: '首页-开动文化科技（北京）有限公司' }
    },
    {
        path: '/ContactUs',
        name: 'ContactUs',
        component: ()=>import('./components/ContactUs.vue'),
        meta: { title: '联系我们-开动文化科技（北京）有限公司' }
    },
    {
        path: '/Aboutus',
        name: 'Aboutus',
        component: ()=>import('./components/Aboutus.vue'),
        meta: { title: '关于我们-开动文化科技（北京）有限公司' }
    },
    {
        path: '/ServiceProcess',
        name: 'ServiceProcess',
        component: ()=>import('./components/ServiceProcess.vue'),
        meta: { title: '服务流程-开动文化科技（北京）有限公司' }
    },
    {
        path: '/Examples',
        name: 'Examples',
        component: ()=>import('./components/Examples.vue'),
        meta: { title: '行业案例-开动文化科技（北京）有限公司' }
    },
    {
        path: '/Err404',
        name: 'Err404',
        component: ()=>import('./components/Tools/Err404.vue'),
        meta: { title: '404：未找到此页面' }
    },
    {
        path: '/:pathMatch(.*)*',
        redirect: '/Err404'
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// 路由守卫，切换页面时修改标题
router.beforeEach((to, from, next) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    } else {
        document.title = '开动文化科技（北京）有限公司'
    }
    next()
})

export default router
