angular - In angular2 I'm using canActivate but when it returns false it still goes to the route -


in angular2 i'm using canactivate when returns false still goes route.

here code below:

 canactivate(route: activatedroutesnapshot, state: routerstatesnapshot): boolean {         this.isauthrequired = route.data.isauthrequired;         this.iscompanyview = route.data.iscompanyview;          return this.init();     } 

this code returns true or false depending on routes data e.g. isauthrequired etc.

is still meant go route? because , shows blue screen no console errors i'm wanting redirect homepage or atleast stay on previous page.

how feature mean't work , have suggestions.

make sure returning boolean or promise or observar init() method. returning true init() navigate selected routing. returning false prevent page navigation current screen.

something below :-

init(): boolean{     /* application logic */      return true; }  canactivate(route: activatedroutesnapshot, state: routerstatesnapshot): boolean {     this.isauthrequired = route.data.isauthrequired;     this.iscompanyview = route.data.iscompanyview;      return this.init();   } 

i hope can you.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -