spring-cloud/mobile-web/src/config/router.js

249 lines
4.9 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import Vue from 'vue';
import Router from 'vue-router';
import { getAccessToken } from '../utils/cache';
Vue.use(Router);
const routes = [
{
path: '*',
redirect: '/home'
},
{
name: 'home',
component: () => import('../page/index'),
meta: {
title: ''
}
},
{
path: '/login',
component: () => import('../page/account/phonelogin'),
meta: {
title: ''
}
},
// {
// path: '/login/password',
// component: () => import('../page/account/password'),
// meta: {
// title: '登录'
// }
// },
// {
// path: '/login/phone',
// component: () => import('../page/account/phonelogin'),
// meta: {
// title: '手机号登录'
// }
// },
// {
// path: '/login/register',
// component: () => import('../page/account/register'),
// meta: {
// title: '注册'
// }
// },
{
path: '/user/index',
component: () => import('../page/user/index'),
name: 'user',
meta: {
title: ''
}
},
{
path: '/user/info',
component: () => import('../page/user/info/detail'),
name: 'user',
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/address',
component: () => import('../page/user/address/list'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/address/edit',
component: () => import('../page/user/address/edit'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/favorite',
component: () => import('../page/user/favorite/list'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/coupon',
component: () => import('../page/coupon/list'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/order',
component: () => import('../page/user/order/list'),
meta: {
title: ''
},
},
{
path: '/user/order/:id',
component: () => import('../page/user/order/list'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/order/info/:id',
component: () => import('../page/user/order/info'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/order/logistics/:id',
component: () => import('../page/user/order/logistics'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/user/aftersale',
component: () => import('../page/user/aftersale/list'),
meta: {
title: ''
}
},
{
path: '/user/aftersale/apply/:orderId',
component: () => import('../page/user/aftersale/apply'),
meta: {
title: ''
}
},
{
path: '/user/aftersale/detail/:orderId',
component: () => import('../page/user/aftersale/detail'),
meta: {
title: ''
}
},
{
path: '/user/aftersale/track/:id/:serviceNumber',
component: () => import('../page/user/aftersale/track'),
meta: {
title: ''
}
},
{
name: '/product/search',
path: '/product/search',
component: () => import('../page/product/search'),
meta: {
title: ''
}
},
{
path: '/product/:id',
component: () => import('../page/product/detail'),
meta: {
title: ''
}
},
{
path: '/products/list',
component: () => import('../page/product/list'),
meta: {
title: ''
}
},
{
name: 'cart',
component: () => import('../page/cart/index'),
meta: {
title: '',
requireAuth: true,
}
},
{
path: '/order',
component: () => import('../page/shipping/order'),
meta: {
title: '',
requireAuth: true,
}
},
{
name: 'category',
component: () => import('../page/category/index'),
meta: {
title: ''
}
},
{
path: '/coupon/fetch',
component: () => import('../page/coupon/fetch'),
meta: {
title: ''
}
},
{
path: '/pay',
component: () => import('../page/pay/index'),
meta: {
title: '',
requireAuth: true,
}
}
];
// add route path
routes.forEach(route => {
route.path = route.path || '/' + (route.name || '');
});
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();
});
export {
router
};