import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";
const { ROUTER_BASEURL } = require('../../src/config')
//单个引入2个方式
// component: () => import(/* webpackChunkName: "about" */ "../views/About.vue")
// import Home from "../views/Home.vue";

// 项目其他页面路由（推荐使用）
import lingyunge from "../router/lingyunge/lingyunge";

// vue项目自带路由
const routes = [
    //非项目router

];

// const routers = [...routes, ...lingyunge];

const router = createRouter({
    // history: createWebHashHistory, hash模式
    history: createWebHistory(ROUTER_BASEURL),
    routes: [...routes, ...lingyunge]
});


router.beforeEach((to, from, next) => {
    if (to.meta.title) { // 判断是否有标题
        document.title = to.meta.title;
    }
    if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
        if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
            //处理移动端的业务逻辑
            if (to.path.indexOf('/wap') > -1) {
                console.log(to);
                next();
            } else {
                to.path = to.path + '/wap';
                console.log(to);
                next(to.path);
            }
        } else {
            //处理电脑端的业务逻辑
            if (to.path.indexOf('/wap') > -1) {
                let path = to.path.replace("/wap", '');
                next(path);
            } else {
                next();
            }
        }
    }

});
// 配置base属性 声明路由根目录


export default router;

