使用 Angular2 时获取完整 URL

Jas*_*son 5 angular

我原以为通过 Angular2 的所有工作找到这些信息会很简单,但显然不是......

1) 如何获取Angular2 中激活路由的完整url?我知道我可以打电话,window.location.href但想知道是否有 Angular 方式。

2)有没有办法“建立”一个网址?如果我知道我想要的路线和所述路线的参数,我可以构建完整的url 吗?

Sum*_*ant 0

如果你构建了 url 并想要导航,你可以使用navigateByUrl方法

router.navigateByUrl("/team/33/user/11");
// Navigate without updating the URL
router.navigateByUrl("/team/33/user/11", { skipLocationChange: true});
Run Code Online (Sandbox Code Playgroud)

https://angular.io/docs/ts/latest/api/router/index/Router-class.html#!#navigateByUrl-anchor