缺少产品/物品/等的角度模式

我有一个简单的问题,很可能已经被回答了,但我找不到。

假设我有一个带有组件的Angular应用程序,该组件应显示数据库中某个产品的详细信息,并提供路径:

http://example.com/product/1564

当存在具有特定ID的产品时,一切都非常清楚。但是,如果没有这样的产品,我应该如何处理呢?

  • Create a separate component and navigate there with router.navigateByUr()? But AFAIK for that I need to define a route. Somebody can come there from outside, that I do not want to happen. Is it possible to define a hidden route accessible only from the code?
  • Use the custom matcher in the definition of the route? It should check if the product exists or not. This might be an extra roundtrip to the API of my site.
  • Use good number of *ngIfs in the template of my component?
  • Any other/better approach?

在这种情况下我该怎么办?

评论