我有一个设置了参数的路由器
@RouteConfig([
{
path: 'article/:id/:title',
name: 'ArticleContent',
component: ArticleComponent
}
])
在其他地方,我正在尝试读取看起来像这样的链接的 href 值
href="article/45/titlehere"
并使用 Router navigate 方法路由到该 url,而不必将其分解为单个参数。 Angular2 中有直接的方法来做到这一点吗?像这样?
_router.navigate("article/34/titlehere")
这个不行,继续获取
EXCEPTION: TypeError: linkParams.reduce is not a function
附言。已正确设置为站点根目录
最佳答案
如果你有 url 作为字符串,你应该使用 navigateByUrl Router对象的方法:
navigateByUrl(url: string, _skipLocationChange?: boolean) : Promise<any>
Navigate to a URL. Returns a promise that resolves when navigation is complete. It's preferred to navigate with navigate instead of this method, since URLs are more brittle.
If the given URL begins with a /, router will navigate absolutely. If the given URL does not begin with /, the router will navigate relative to this component.
关于angular - 如何导航到 Angular2 中的确切 url 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35805244/