前端:优惠劵列表
前端:增加路由的认证拦截
This commit is contained in:
@@ -20,8 +20,8 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV == 'development') {
|
||||
|
||||
// baseUrl = 'http://127.0.0.1';
|
||||
// baseUrl = 'http://180.167.213.26:18099';
|
||||
// dataSources = 'remote';
|
||||
dataSources = 'local';
|
||||
dataSources = 'remote';
|
||||
// dataSources = 'local';
|
||||
|
||||
export {
|
||||
baseUrl,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import Vue from 'vue';
|
||||
import Router from 'vue-router';
|
||||
|
||||
import { getAccessToken } from '../utils/cache';
|
||||
|
||||
Vue.use(Router);
|
||||
|
||||
const routes = [
|
||||
@@ -84,7 +86,8 @@ const routes = [
|
||||
path: '/user/coupon',
|
||||
component: () => import('../page/user/coupon/list'),
|
||||
meta: {
|
||||
title: '我的优惠券'
|
||||
title: '我的优惠券',
|
||||
requireAuth: true,
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -202,10 +205,23 @@ routes.forEach(route => {
|
||||
const router = new Router({ routes });
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 判断是否需要认证
|
||||
const requireAuth = to.meta && to.meta.requireAuth;
|
||||
if (requireAuth) {
|
||||
if (!getAccessToken()) { // 未登陆
|
||||
next({
|
||||
path: '/login',
|
||||
query: {redirect: to.fullPath} // 将跳转的路由path作为参数,登录成功后跳转到该路由
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 处理标题
|
||||
const title = to.meta && to.meta.title;
|
||||
if (title) {
|
||||
document.title = title;
|
||||
}
|
||||
// 继续路由
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user