繁体   English   中英

Angular 2路由器:多个路由参数

[英]Angular 2 Router: multiple route parameters

我想要一个带有该URL的路线

/collections/:collectionId/books/:bookId/:title

例如

/collections/10/books/456678/my-book.html

在我的app-routing.module.ts文件中

{path: 'collections/:collectionId/books/:bookId/:title', component: BookDetailsComponent},

是否可以不使用嵌套的路由器插座?

我试过了

this.router.navigate(['/collections',{collectionId: 10, bookId: 456678, title: "my-book.html"}]);

但得到了一个错误

Cannot match any routes. URL Segment: 'collections;collectionId=10;bookId=456678;title=my-book.html'

如果我将参数作为数组传递,

this.router.navigate(['/collections', 10, 456678, "my-book.html"]);

我明白了

Error: Cannot match any routes. URL Segment: 'collections/10/456678/my-book.html

我设法在“收藏”路线下使用“书籍”儿童路线实现我想要的东西,但我想在没有嵌套路线的情况下做到这一点。

谢谢

它应该是

this.router.navigate(['/collections', '10', 'books', '456678', "my-book.html"]);

这些数字的引号不是必需的,但我认为这是一个好习惯。

暂无
暂无

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

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