|
|
@@ -1,11 +1,14 @@
|
|
|
import Vue from 'vue';
|
|
|
import VueRouter from 'vue-router';
|
|
|
+import store from '../store';
|
|
|
+import { MessageBox } from 'element-ui';
|
|
|
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
|
|
|
const originalPush = VueRouter.prototype.push;
|
|
|
VueRouter.prototype.push = function push(location) {
|
|
|
return originalPush.call(this, location).catch(err => err);
|
|
|
};
|
|
|
Vue.use(VueRouter);
|
|
|
+import eventBus from '../eventBus';
|
|
|
|
|
|
const routes = [
|
|
|
{
|
|
|
@@ -69,7 +72,8 @@ const routes = [
|
|
|
name: 'my',
|
|
|
component: () => import('../views/My.vue'),
|
|
|
meta: {
|
|
|
- title: '我的NFT'
|
|
|
+ title: '我的NFT',
|
|
|
+ checkLogin: true
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
@@ -95,4 +99,28 @@ const router = new VueRouter({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+router.beforeEach((to, from, next) => {
|
|
|
+ if (!store.state.userInfo) {
|
|
|
+ store
|
|
|
+ .dispatch('getUserInfo')
|
|
|
+ .then(() => {
|
|
|
+ next();
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ if (to.meta.checkLogin) {
|
|
|
+ MessageBox('用户未登录,是否立即登录', '提示', {
|
|
|
+ confirmButtonText: '立即登录'
|
|
|
+ }).then(() => {
|
|
|
+ eventBus.$emit('login');
|
|
|
+ });
|
|
|
+ next('/');
|
|
|
+ } else {
|
|
|
+ next();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ next();
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
export default router;
|