0

hi I need to detect in my if rout has canActivate, but can't find how to do that.

service`

canActivate() {
        this.userLogedin = localStorage.getItem('AUTHENTICATION');

        //I need check here if rout has canActivate

        if (this.userLogedin === 'false') {
            this.router.navigateByUrl('');

            return false;
        }else {
            return true;
        }
    }
Aram Mkrtchyan
  • 2,690
  • 4
  • 31
  • 47
  • i think you're misunderstanding the use of `canActivate`. It will only be called by the routing system if the route in question is guarded by a Guard (i.e. a class that implements the canActivate method). So, in normal use cases, you don't have to 'know if route has canActivate'. `canActivate` will only be called if the current route actually has a guard in place – snorkpete Mar 13 '17 at 12:50
  • so I have two pages when i logout from account in first page will redirect to home page in second page will stay on that page.How can I do that, sorry for bad english :) – Aram Mkrtchyan Mar 13 '17 at 12:54
  • is it that you have two pages, page1 and page2. If you are logged out, going to page1 will redirect to page2 and going to page2 will stay on page2? – snorkpete Mar 13 '17 at 13:02
  • you can access on second page when logout. so no when I logout it redirec to home page from two existed pages, but it will not redirect from second page – Aram Mkrtchyan Mar 13 '17 at 13:28
  • sounds like you might want your guard to only apply to the first page, not the second. In other words, in your router configuration, only apply the guard to the route to the first page and don't apply the guard to the second – snorkpete Mar 13 '17 at 18:23

0 Answers0