I am attempting to use the canActivate feature on my app routing, however whenever I compile the app the log shows constantly refreshing with fail messages that I had console.log()'d out for visibility.
Is there something I am missing here?
You are redirecting to the wrong route in your canActivate
method. Redirect to login
. Here are the change you need to make:
// if not logged in, navigate to login screen
this.router.navigate(['login'], {queryParams: {returnUrl: state.url}});
When you are redirecting to ''
, it goes again to the canActivate
guard, hence the infinite loop.
this.router.navigate([''], {queryParams: {returnUrl: state.url}});
will get executed everytime when not logged in, thus causing your infinite redirects as in your router config
{path: '', component: HomepageComponent, canActivate: [AuthGuard]},
Add an explicitly path for an e.g. LoginComponent.
And {path: '**', redirectTo: ''}
should also point to some kind of CatchUnmatchedPathComponent where a User gets some kind of 404 page represented.
I have site which contains many links. User can open links in new window. User can log out from one window. If they do so and click on the other window of my site then I want to give an alert to the ...
I have site which contains many links. User can open links in new window. User can log out from one window. If they do so and click on the other window of my site then I want to give an alert to the ...
i need create this function to improve my code. I need give to the a color given by the caller of the function, how can i do this? Here the code: function visualizza(array, div, color) { div....
i need create this function to improve my code. I need give to the a color given by the caller of the function, how can i do this? Here the code: function visualizza(array, div, color) { div....
I'm trying to mimic the new Tumblr Text Post that removes blockquotes so all the important text is visible in a 250px text post without having to scroll. Of course Tumblr hasn't updated their entire ...
I'm trying to mimic the new Tumblr Text Post that removes blockquotes so all the important text is visible in a 250px text post without having to scroll. Of course Tumblr hasn't updated their entire ...
I've searched for solutions on Google and SO but still cannot find an answer. They all stop at "Add item to cart" or "increase/decrease quantity" but never on calculating the Total, which is annoying! ...
I've searched for solutions on Google and SO but still cannot find an answer. They all stop at "Add item to cart" or "increase/decrease quantity" but never on calculating the Total, which is annoying! ...