首页 > 解决方案 > How to determine route prior to route guard Angular?

问题描述

so I have lets say 2 routes '/admin-route' and '/superuser-route' and both require 'admin' and 'superuser' privileges respectively to access these routes.

When user clicks on this route I check privileges and if they're false for that user I activate a '/no-access' route guard.

The challenge is that I have breadcrumbs in my app and if the user gets a no-access state I want to display in the breadcrumbs which route he previously accessed.

So if user tries to access '/admin-route' and he doesn't have admin rights the no-access route guard kicks in and I want to have displayed in the breadcrumbs 'Admin' and the same if user tries to access '/superuser-route' and gets no-access page I want 'Superuser' breadcrumb.

I'm having a challenging time figuring out how to tell the route guard which was the previous route to be able to display the correct breadcrumb.

I hope this isn't too confusing and any help is appreciated!

标签: angularroutesbreadcrumbsangular-route-guards

解决方案


在路由守卫或中央服务中有逻辑。

每条有效路线都会更新该属性的值。

当用户移动到无效路线时,使用该属性的值。

像导航结束的实例,--根据您的逻辑使用检查更新属性


推荐阅读