xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

window.VUE_ROUTER

window.VUE_ROUTER

全局 VueRouter 实例

import Vue from 'vue';
import routers from '@/routers/index';
import App from '@/views/app.vue';
import store from '@/store/index';
import '@/utils/iconfont.js';

import ElementUI from 'element-ui';
import VueRouter from 'vue-router';

import 'animate.css';
import 'element-ui/lib/theme-chalk/index.css';
import 'element-ui/lib/theme-chalk/display.css';
import 'font-awesome/css/font-awesome.min.css';
import '@/styles/app.scss';

import * as PACKAGE from '../package.json';



// disable vue devtool
Vue.config.productionTip = false;

ElementUI.Dialog.props.closeOnClickModal.default=false;
Vue.use(ElementUI, { size: 'small' });

Vue.use(VueRouter);


const router = new VueRouter({
    mode: 'history',
    routes: routers,
});

window.VUE_ROUTER = router;

router.beforeEach((to, from, next) => {
    const token = UtilCache.getLocalItem('token');
    if (!token && to.path !== '/login') {
        next({ name: 'Login' });
    } else {
        next();
    }
});

// eslint-disable-next-line no-new
new Vue({
    router,
    store,
    render: h => h(App),
}).$mount('#app');



        console.log('🔥 this.$route', this.$route);
        console.log('🔥 window.VUE_ROUTER', window.VUE_ROUTER, window.VUE_ROUTER.routes);

✅ OK

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-05-08 12:01  xgqfrms  阅读(387)  评论(1编辑  收藏  举报