import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
    {
        path: '*',
        redirect: '/login',
        navShow: false
    },
    {
        name: 'login',
        component: () => import('./views/login'),
        meta: {
            title: '登录',
            navShow: false
        }
    },
    {
        name: 'verify',
        component: () => import('./views/SecurityVerify'),
        meta: {
            title: '安全验证'
        }
    },
    {
        name: 'presentRegister',
        component: () => import('./views/PresentRegister'),
        meta: {
            title: '礼物登记',
            navShow: false
        }
    },
    {
        name: 'index',
        component: () => import('./views/index'),
        meta: {
            title: '首页',
            navShow: true
        }
    },
    {
        name: 'me',
        component: () => import('./views/me'),
        meta: {
            title: '我的',
            navShow: true
        }
    },
    {
        name: 'share',
        component: () => import('./views/share'),
        meta: {
            title: '分享海报',
            navShow: false
        }
    },
    {
        name: 'giftDetail',
        component: () => import('./views/giftDetail'),
        meta: {
            title: '礼品卡',
            navShow: false
        }
    }
];

// add route path
routes.forEach(route => {
    route.path = route.path || '/' + (route.name || '');
});

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }
    next();
});

export {
    router
};
