import Vue from 'vue'
import Router from 'vue-router'
import store from '../vuexPre'
import axios from 'axios'
import RongIM from '../RongIM'

Vue.use(Router);

const router = new Router({
    routes: [{
        path: '/',
        redirect: 'home'
    }, {
        path: '/home',
        name: 'home',
        component: () =>
            import ('../pagesPre/Home')
    }, {
        path: '/list',
        name: 'list',
        component: () =>
            import ('../pagesPre/List')
    }, {
        path: '/404',
        name: '404',
        component: () =>
            import ('../pagesPre/404')
    }]
});
router.beforeEach((to, from, next) => {
    console.log(to.path)
        //console.log(to);
    if (/^\/http/.test(to.path)) {
        console.log(Vue.$baseUrl);
        let url = to.path.replace('/', '');
        let params = [];
        if (to.query) {
            for (let key in to.query) {
                if (to.query.hasOwnProperty(key)) {
                    params.push(`${key}=${to.query[key]}`);
                }
            }
        }
        if (params.length > 0) {
            url += `?${params.join('&')}`;
        }
        window.open(url);
        return;
    }






    if (!to.matched.length) {
        next('/404');
    } else {
        next();
    }
});
router.afterEach((to, from) => {
    window.onresize();
});

function getQueryString(name) {
    let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
    let r = window.location.search.substr(1).match(reg)
    if (r != null) return unescape(r[2])
    return null
}


export default router;