0

I am trying to implement functionality where I have a list of products and when I click on one of them it will open a details page with suggested products.

It is working fine if the user provides an existing product id, but when the user manually changes the id of the product to something that is not valid, I need to cancel the navigation, show a snack bar alert and stay where the page was.

I don't want to redirect to an error page. I'd prefer to stay at the same place and show the message. I cannot use a guard because it would have to fetch the product from the db.

Jennifer S
  • 1,419
  • 1
  • 24
  • 43
grusio
  • 1
  • Does this answer your question? [Is it possible to stop router navigation based on some condition](https://stackoverflow.com/questions/42808818/is-it-possible-to-stop-router-navigation-based-on-some-condition) – Roberto Zvjerković Dec 08 '20 at 15:57
  • 1
    better to show product page with the product not found so the user can able to know its not a valid product id – Arsalan Akhtar Dec 08 '20 at 16:00
  • @ritaj it does not solve the problem. Resolver is called after all guards are finished. I cannot check if a product is in the DB in canDeactivate because then I will have to fetch it once again in the resolver. – grusio Dec 08 '20 at 16:17
  • 1
    canDeactivate can also return an observable – Roberto Zvjerković Dec 08 '20 at 16:28
  • Observable | Promise | boolean | UrlTree> what means it cannot be used to return real data as resolve does. – grusio Dec 09 '20 at 08:35

0 Answers0