【发布时间】:2023-03-26 18:42:01
【问题描述】:
在 angular2 中如何导航到需要 id 的另一条路线?
我正在使用这个路由器版本:"@angular/router": "2.0.0-rc.1"
这是我要导航到的 app.component 路由:
{ path: '/blog/:slug', component: BlogArticle, as: 'BlogArticle' }
这是我试图导航到它的另一个组件:
this.router.navigate(['blog', { slug: blogId }]);
基本上我想知道如何从组件和视图中导航到带有 id 的 url。
视图中的当前尝试:
[routerLink]=" ['/blog', {slug: blogId }]"
组件中的当前尝试:
this.router.navigate(['blog', { slug: blogId }]);
上述两次尝试均无效,我收到以下错误:
错误:未捕获(承诺中):无法匹配任何路由。
这很奇怪,因为我在 app.component 中设置了路由链接:
@Routes([
{ path: '/blog/:slug', component: BlogArticle, as: 'BlogArticle' }
])
【问题讨论】:
-
尝试从Route定义中删除
as: 'BlogArticle',这可能是RC1路由器的语法错误。 -
好的,我今晚试试
标签: angular