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
Post a Comment