mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	perf: 优化路由守卫
This commit is contained in:
		
							parent
							
								
									c6bd3f11b6
								
							
						
					
					
						commit
						b606fa454d
					
				@ -134,6 +134,10 @@ router.beforeEach((to: toRouteType, _from, next) => {
 | 
				
			|||||||
      else document.title = transformI18n(item.meta.title);
 | 
					      else document.title = transformI18n(item.meta.title);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  /** 如果已经登录并存在登录信息后不能跳转到路由白名单,而是继续保持在当前页面 */
 | 
				
			||||||
 | 
					  function toCorrectRoute() {
 | 
				
			||||||
 | 
					    whiteList.includes(to.fullPath) ? next(_from.fullPath) : next();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  if (userInfo) {
 | 
					  if (userInfo) {
 | 
				
			||||||
    // 无权限跳转403页面
 | 
					    // 无权限跳转403页面
 | 
				
			||||||
    if (to.meta?.roles && !isOneOfArray(to.meta?.roles, userInfo?.roles)) {
 | 
					    if (to.meta?.roles && !isOneOfArray(to.meta?.roles, userInfo?.roles)) {
 | 
				
			||||||
@ -145,7 +149,7 @@ router.beforeEach((to: toRouteType, _from, next) => {
 | 
				
			|||||||
        openLink(to?.name as string);
 | 
					        openLink(to?.name as string);
 | 
				
			||||||
        NProgress.done();
 | 
					        NProgress.done();
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        next();
 | 
					        toCorrectRoute();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      // 刷新
 | 
					      // 刷新
 | 
				
			||||||
@ -175,7 +179,7 @@ router.beforeEach((to: toRouteType, _from, next) => {
 | 
				
			|||||||
          }
 | 
					          }
 | 
				
			||||||
          router.push(to.fullPath);
 | 
					          router.push(to.fullPath);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      next();
 | 
					      toCorrectRoute();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    if (to.path !== "/login") {
 | 
					    if (to.path !== "/login") {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user