在注销时为当前路由激活authguard(角度)

时间:2020-05-20 19:02:54

标签: angular

我的角度应用程序有两条路线,并带有路线防护器

@GetMapping(path = "/getcaroffice")
@ResponseBody
public Iterable<Object[]> getAllCars() {

    Iterable<Object[]> carOffice = carRepository.findCarOffice();
    return carOffice;
}

路由保护器检查用户当前是否登录(通过检查用户BehaviorSubject当前是否为空或设置为用户实例)

const routes: Routes = [
  {path: '', component: MenuComponent},
  {path: 'tableChartGFS', canActivate:[AuthGuard] ,component: TableDataChartGfsComponent},
  {path: 'tableAccount', canActivate:[AuthGuard] ,component: TableDataAccountComponent},
  {path: 'auth', component: AuthComponent}
];

当我登录并转到/ tableAccount路由,然后单击“注销”(将用户BehaviorSubject设置为null)时,由于我不再被允许使用此路由,因此我想重定向到主MenuComponent 。我该如何实现?

1 个答案:

答案 0 :(得分:0)

我通常有一个注销功能来处理注销逻辑,并且我传递了依赖项(路由器,烤面包机,服务等...)

success:function (response) { $('.js-action-edit').html(response) }

相关问题