JavaScript canActivate causing constant refresh - Angular2+

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?

Answer:1

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.

enter image description here

Answer:2

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.

Answer:3

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....

  1. variable javascript style
  2. javascript variable style guide
  3. javascript variable css style
  4. javascript variable in style tag
  5. javascript variable name style

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 ...

  1. remove specific html tags from string javascript
  2. remove specific html tags from string php
  3. remove specific html tags from string c#
  4. remove specific html tag using jquery
  5. remove specific html tag php
  6. remove specific html tags
  7. remove specific html tags from string
  8. remove specific html jquery
  9. remove specific html tags from string java
  10. remove specific html tags from string jquery
  11. remove specific html tags using php
  12. python remove specific html tags
  13. regex remove specific html tags
  14. sed remove specific html tag
  15. jsoup remove specific html tags
  16. regex remove specific html tags javascript
  17. jquery remove specific html tags
  18. javascript remove specific html tags
  19. regex remove specific html tags c#
  20. remove specific div html

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! ...

  1. react redux calculator
  2. react redux calculator example
  3. react redux calculator app
  4. react redux calculator codepen
  5. calculator using react redux
  6. calculator app using react redux
  7. react native redux calculator