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

Dav*_*vid 4 angular

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

/collections/:collectionId/books/:bookId/:title
Run Code Online (Sandbox Code Playgroud)

例如

/collections/10/books/456678/my-book.html
Run Code Online (Sandbox Code Playgroud)

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

{path: 'collections/:collectionId/books/:bookId/:title', component: BookDetailsComponent},
Run Code Online (Sandbox Code Playgroud)

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

我试过了

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

但得到了一个错误

Cannot match any routes. URL Segment: 'collections;collectionId=10;bookId=456678;title=my-book.html'
Run Code Online (Sandbox Code Playgroud)

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

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

我明白了

Error: Cannot match any routes. URL Segment: 'collections/10/456678/my-book.html
Run Code Online (Sandbox Code Playgroud)

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

谢谢

Gün*_*uer 12

它应该是

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

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