简体   繁体   English

Angular2路由:将url部分组合为一个参数

[英]Angular2 Routing: Combine url sections to one parameter

Is it possible to combine url sections into one parameter? 是否可以将网址部分合并为一个参数? Eg I have urls /products/123/234/345 , /products/123/235 and /products/125 . 例如,我有网址/products/123/234/345/products/123/235/products/125 I have a route with path : 'products/:key' . 我有一条路线, path : 'products/:key' Now I want the key to be 123/234/345 for the first url, 123/235 for the second url and 125 for the last url. 现在,我希望第一个URL的密钥为123/234/345 ,第二个URL的密钥为123/234/345 ,最后一个URL的123/235125 Is it possible? 可能吗?

As far as I'm aware of it, you can't do that by using Angular2 router. 据我所知,您无法使用Angular2路由器来做到这一点。 The only way I see that you could try is to define 3 paths corresponding to your use cases, as already explained by Maximus : 我看到您可以尝试的唯一方法是定义3个与用例相对应的路径,如Maximus所解释的:

[path : 'products/:key', path : 'products/:key1/key2', path : 'products/:key1/key2/key3']

If this doesn't solve your problem, you should maybe reconsider the way you are trying to build your app as this is Angular2 way to build routes and any onther tricky way should be avoided. 如果这不能解决您的问题,您可能应该重新考虑尝试构建应用程序的方式,因为这是Angular2的构建路线的方式,应避免任何其他棘手的方式。

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

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