本文介绍了Angular2获取ActivatedRoute网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取来自此的网址:

I want to get the url which comes from this:

this.router.navigate(./somepath, { relativeTo: this.route })

this.route的类型为ActivatedRoute.

我尝试了url: string = route.snapshot.url.join('');,但这给出了一个空字符串.

I tried url: string = route.snapshot.url.join(''); but this gives an empty string.

推荐答案

您可以使用激活的路由来获取活动的URL.

You can use the activated route to get active URL.

import { ActivatedRoute } from '@angular/router';
 constructor(
    private activatedRoute: ActivatedRoute) {
    console.log(activatedRoute.snapshot['_routerState'].url);
}

这篇关于Angular2获取ActivatedRoute网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 11:07