123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- /* eslint-disable camelcase */
- /**
- * 全站路由配置
- *
- * 建议:
- * 1. 代码中路由统一使用name属性跳转(不使用path属性)
- */
- import Vue from 'vue'
- import Router from 'vue-router'
- import { clearLoginInfo } from '@/utils'
- // import MainFrame from "@/views/main.vue"
- // import MainHome from "@/views/common/home.vue"
- Vue.use(Router)
- // 解决路由重复跳转报错
- const originalPush = Router.prototype.push
- const originalReplace = Router.prototype.replace
- // 修改原型对象中的push函数
- Router.prototype.push = function push(location) {
- // @ts-ignore
- return originalPush.call(this, location).catch(err => err)
- }
- // 修改原型对象中的replace函数
- Router.prototype.replace = function replace(location) {
- // @ts-ignore
- return originalReplace.call(this, location).catch(err => err)
- }
- // 开发环境不使用懒加载, 因为懒加载页面太多的话会造成webpack热更新太慢, 所以只有生产环境使用懒加载
- const _import = require('./import-' + process.env.NODE_ENV)
- export const pages = [
- {
- path: "/home",
- component: _import("common/home"),
- name: "home",
- meta: { title: "首页", sidebar: false, icon: "index", isTab: false }
- }, {
- path: "/prod/product/list",
- component: _import("modules/prod/prodList"),
- name: "prodList",
- meta: { title: "产品管理", sidebar: true, icon: "product", isTab: true }
- }, {
- path: "/prod/product/edit/:id",
- component: _import("modules/prod/prodInfo"),
- name: "prodInfo",
- meta: { title: "产品信息", sidebar: false, icon: "", isTab: false }
- }, {
- path: "/prod/category/list",
- component: _import("modules/prod/category"),
- name: "categoryList",
- meta: { title: "分类管理", sidebar: true, icon: "inbox", isTab: true }
- }, {
- path: "/user/list",
- component: _import("modules/user/user"),
- name: "userList",
- meta: { title: "用户管理", sidebar: true, icon: "user", isTab: true }
- }, {
- path: "/order/list",
- component: _import("modules/order/order"),
- name: "orderList",
- meta: { title: "订单管理", sidebar: true, icon: "order", isTab: true }
- }, {
- path: "/liveroom/list",
- component: _import("modules/liveroom/liveroomList"),
- name: "liveroomList",
- meta: { title: "直播间管理", sidebar: true, icon: "broadcast", isTab: true }
- }, {
- path: "/liveroom/edit/:id",
- component: _import("modules/liveroom/liveroomEdit"),
- name: "liveroomEdit",
- meta: { title: "直播间信息", sidebar: false, icon: "", isTab: false }
- }, {
- path: "/liveroom/liveroom-product-jump-record/:id",
- component: _import("modules/liveroom/liveroomProductJumpRecord"),
- name: "liveroomProductJumpRecord",
- meta: { title: "直播间商品跳转记录", sidebar: false, icon: "", isTab: false }
- }, {
- path: "/liveroom/product/:id",
- component: _import("modules/liveroom/liveroomProd"),
- name: "liveroomProd",
- meta: { title: "直播间商品库", sidebar: false, icon: "", isTab: false }
- }, {
- path: "/liveroom/consults/:id",
- component: _import("modules/liveroom/liveroomConsults"),
- name: "liveroomConsults",
- meta: { title: "直播间客户咨询", sidebar: false, icon: "", isTab: false }
- },
- ]
- const routes = [
- { path: '/404', component: _import('common/404'), name: '404', meta: { title: '未找到该页面' } },
- { path: '/login', component: _import('common/login'), name: 'login', meta: { title: '登录' } },
- {
- path: "/",
- component: _import("main"),
- name: 'main',
- redirect: { name: 'home' },
- meta: { title: '主入口整体布局' },
- children: pages,
- beforeEnter(to: string, from: string, next: Function) {
- // @ts-ignore
- let authorization = Vue.cookie.get('Authorization')
- if (!authorization || !/\S/.test(authorization)) {
- clearLoginInfo()
- next({ name: 'login' })
- }
- next()
- }
- }
- ]
- const router = new Router({
- mode: 'hash',
- // @ts-ignore
- routes,
- // @ts-ignore
- scrollBehavior: () => ({ y: 0 }),
- })
- export default router
|