简体   繁体   English

角度:多个嵌套路线

[英]Angular: Multiple nested routes

Summary 摘要

  • I have a list of products situated on a product page (url.com/products) 我在产品页面(url.com/products)上列出了产品列表
  • When I click on a product i'm presented with a summary and a link to issues with that product (url.com/products/22) - (22 being the product id) 当我单击某个产品时,会显示摘要和该产品问题的链接(url.com/products/22)-(22为产品ID)
  • When i click on the link to view issues, I become stuck. 当我单击链接查看问题时,我陷入了困境。

What I have so far 到目前为止我有什么

I can display the list of products fine, and I can also display a page once clicking on a product and the URL changes to "url.com/products/10". 我可以很好地显示产品列表,也可以在单击产品后显示页面,并且URL更改为“ url.com/products/10”。 So that's working fine with the below. 所以下面的工作正常。

 <a [routerLink] = "['/product', product.productID]"> {{ product.productName }} </a> 

Question Is it possible to use router links to achieve the following? 问题是否可以使用路由器链接实现以下目标?

"url.com/products/10/issues/24" “url.com/products/10/issues/24”

  • Products: The products page which displays a list of products 产品:显示产品列表的产品页面
  • 10: The selected product which has an ID of 10 10:ID为10的所选产品
  • Issues: A issues list page related to that product 问题:与该产品相关的问题列表页面
  • 24:The selected issue which has an ID of 24 24:选定的ID为24的问题

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thank you. 谢谢。

Yes you can do that in the following way: 是的,您可以通过以下方式进行操作:

  • For list of issues: [routerLink] = "['/product', product.productID, 'issues']" . 对于问题列表: [routerLink] = "['/product', product.productID, 'issues']"
    This will generate a link to /product/10/issues/ 这将生成一个指向/product/10/issues/

  • For a particular issue: [routerLink] = "['/product', product.productID, 'issues', issueID]" . 对于特定问题: [routerLink] = "['/product', product.productID, 'issues', issueID]"
    This will generate a link to /product/10/issues/24 这将生成一个指向/product/10/issues/24

You can get more details over here . 您可以在此处获得更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM