热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

关于vueelementadmin中的router问题

在router.beforeEach中添加身份验证条件之后

在router.beforeEach中添加身份验证条件之后

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
router.beforeEach((to, from, next) => {

  NProgress.start() // start progress bar

  if (getToken()) {

    // determine if there has token

    /* has token*/

    if (to.path === '/login') {

      next({ path: '/' })

      NProgress.done() // if current page is dashboard will not trigger    afterEach hook, so manually handle it

    } else {





      if(store.getters.userRole == 1 || store.getters.userRole == 2){

        router.addRoutes(asyncRoutes) // 动态添加可访问路由表

        // console.log(router)

        // console.log(to)

        next({ ...to, replace: true })

        // next({ path: '/' })

      }else{

        router.addRoutes(constantRoutes) // 动态添加可访问路由表

        next({ ...to, replace: true })

      }

    }

  } else {

    // alert('获取失败')

    /* has no token*/

    if (whiteList.indexOf(to.path) !== -1) {

      // 在免登录白名单,直接进入

      next()

    } else {

      next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页

      NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it

    }

  }

})

浏览器报错内存泄漏,Maximum call stack size exceeded

下面是我的路由

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
export const cOnstantRoutes= [

  {

    path: '/redirect',

    component: Layout,

    hidden: true,

    children: [

      {

        path: '/redirect/:path*',

        component: () => import('@/views/redirect/index')

      }

    ]

  },

  {

    path: '/login',

    component: () => import('@/views/login/index'),

    hidden: true

  },

  {

    path: '/auth-redirect',

    component: () => import('@/views/login/authredirect'),

    hidden: true

  },

  {

    path: '/404',

    component: () => import('@/views/errorPage/404'),

    hidden: true

  },

  {

    path: '/401',

    component: () => import('@/views/errorPage/401'),

    hidden: true

  },

  {

    path: '',

    component: Layout,

    redirect: 'dashboard',

    children: [

      {

        path: 'dashboard',

        component: () => import('@/views/dashboard/index'),

        name: 'Dashboard',

        meta: { title: 'dashboard', icon: 'dashboard', noCache: true, affix: true }

      }

    ]

  },

  {

    path: 'dashboard',

    component: () => import('@/views/dashboard/index'),

    // name: 'Dashboard',

    meta: { title: 'dashboard', icon: 'dashboard', noCache: true, affix: true }

  }

  // {

  //   path: '/documentation',

  //   component: Layout,

  //   children: [

  //     {

  //       path: 'index',

  //       component: () => import('@/views/documentation/index'),

  //       name: 'Documentation',

  //       meta: { title: 'documentation', icon: 'documentation', affix: true }

  //     }

  //   ]

  // },

  // {

  //   path: '/guide',

  //   component: Layout,

  //   redirect: '/guide/index',

  //   children: [

  //     {

  //       path: 'index',

  //       component: () => import('@/views/guide/index'),

  //       name: 'Guide',

  //       meta: { title: 'guide', icon: 'guide', noCache: true }

  //     }

  //   ]

  // }

]



export default new Router({

  // mode: 'history', // require service support

  scrollBehavior: () => ({ y: 0 }),

  routes: constantRoutes

})



export const asyncRoutes = [



  // 初级系统不支持用户管理

  // {

  //   path:'/users',

  //   component:Layout,

  //   children:[

  //     {

  //       path:'',

  //       component:() => import('@/views/users/users'),

  //       name:'users',

  //       meta: { title: 'users', icon: 'peoples', noCache: true }

  //     }



  //   ]

  // },

  // {

  //   path: '',

  //   component: Layout,

  //   redirect: 'dashboard',

  //   children: [

  //     {

  //       path: 'dashboard',

  //       component: () => import('@/views/dashboard/index'),

  //       name: 'Dashboard',

  //       meta: { title: 'dashboard', icon: 'dashboard', noCache: true, affix: true }

  //     }

  //   ]

  // },



  // {

  //   path: '/redirect',

  //   component: Layout,

  //   hidden: true,

  //   children: [

  //     {

  //       path: '/redirect/:path*',

  //       component: () => import('@/views/redirect/index')

  //     }

  //   ]

  // },

  {

    path: '/aisle',

    component: Layout,

    children: [

      {

        path: '',

        component: () => import('@/views/aisle/aisle'),

        name: 'aisle',

        meta: { title: 'aisle', icon: 'tree', noCache: true }

      }

    ]

  },



推荐阅读
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了一个React Native新手在尝试将数据发布到服务器时遇到的问题,以及他的React Native代码和服务器端代码。他使用fetch方法将数据发送到服务器,但无法在服务器端读取/获取发布的数据。 ... [详细]
  • 基于移动平台的会展导游系统APP设计与实现的技术介绍与需求分析
    本文介绍了基于移动平台的会展导游系统APP的设计与实现过程。首先,对会展经济和移动互联网的概念进行了简要介绍,并阐述了将会展引入移动互联网的意义。接着,对基础技术进行了介绍,包括百度云开发环境、安卓系统和近场通讯技术。然后,进行了用户需求分析和系统需求分析,并提出了系统界面运行流畅和第三方授权等需求。最后,对系统的概要设计进行了详细阐述,包括系统前端设计和交互与原型设计。本文对基于移动平台的会展导游系统APP的设计与实现提供了技术支持和需求分析。 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • importjava.util.ArrayList;publicclassPageIndex{privateintpageSize;每页要显示的行privateintpageNum ... [详细]
  • 关键词:Golang, Cookie, 跟踪位置, net/http/cookiejar, package main, golang.org/x/net/publicsuffix, io/ioutil, log, net/http, net/http/cookiejar ... [详细]
  • 标题: ... [详细]
  • 本文介绍了在wepy中运用小顺序页面受权的计划,包含了用户点击作废后的从新受权计划。 ... [详细]
  • 如何查询zone下的表的信息
    本文介绍了如何通过TcaplusDB知识库查询zone下的表的信息。包括请求地址、GET请求参数说明、返回参数说明等内容。通过curl方法发起请求,并提供了请求示例。 ... [详细]
  • 模板引擎StringTemplate的使用方法和特点
    本文介绍了模板引擎StringTemplate的使用方法和特点,包括强制Model和View的分离、Lazy-Evaluation、Recursive enable等。同时,还介绍了StringTemplate语法中的属性和普通字符的使用方法,并提供了向模板填充属性的示例代码。 ... [详细]
  • 本文介绍了如何使用JSONObiect和Gson相关方法实现json数据与kotlin对象的相互转换。首先解释了JSON的概念和数据格式,然后详细介绍了相关API,包括JSONObject和Gson的使用方法。接着讲解了如何将json格式的字符串转换为kotlin对象或List,以及如何将kotlin对象转换为json字符串。最后提到了使用Map封装json对象的特殊情况。文章还对JSON和XML进行了比较,指出了JSON的优势和缺点。 ... [详细]
  • EPPlus绘制刻度线的方法及示例代码
    本文介绍了使用EPPlus绘制刻度线的方法,并提供了示例代码。通过ExcelPackage类和List对象,可以实现在Excel中绘制刻度线的功能。具体的方法和示例代码在文章中进行了详细的介绍和演示。 ... [详细]
  • oracle恢复失败,RMAN数据库恢复失败解决一例
    问题:这是一个从RAC环境的数据库的RAMN备份恢复到一个单机数据库的操作。当恢复数据文件和恢复正常,但在open数据库时出报下面的错误。--rman备 ... [详细]
author-avatar
马婷婷0514_761
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有