src/router/index.js

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

Vue.use(Router);

const router = new Router({
    routes: [{
            name: 'home',
            path: '/',
            meta: {
                title: '首页'
            },
            component: Home
        },
        {
            name: 'productList',
            path: '/productList',
            meta: {
                title: '商品列表'
            },
            component: ProductList
        },
        { /* 404必须是最后一个路由 */
            name: '404',
            path: '*',
            meta: {
                title: '找不到页面'
            },
            component: NotFound
        }
    ]
});


router.beforeEach((to, from, next) => {

    /* 路由发生变化修改页面title */
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();

});
export default router;
Logo

前往低代码交流专区

更多推荐