import {createRouter, createWebHistory,createWebHashHistory} from "vue-router";

// const routerHistory = createWebHistory();
const routerHash = createWebHashHistory();

const router = createRouter({
    // history: routerHistory,
    history: routerHash,
    routes: [
        {
            path: "/",
            name: "Home",
            component: () => import ("../views/Home/index.vue"),
            meta: {requireAuth: false},
        },  
        {
            path: "/login",
            name: "login",
            component: () => import ("../views/Login/Login.vue"),
            meta: {requireAuth: false},
        },
        {
            path: "/map",
            name: "Map",
            component: () => import ("../views/Map/index.vue"),
            meta: {newWindow: true},
        },
    ]
});
router.beforeEach((to, form, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    } else {
        document.title = '农发合作社管理平台' //此处写默认的title
    }
    let token = localStorage.getItem('Token')
    if (to.path=='/' && !token) {
        next('/login');
    }else{
        next();
    }
    
  	
})



export default router;
