【发布时间】:2019-12-22 15:01:18
【问题描述】:
我的应用在root 下运行。我想提取root之后的任何文本。
在下面的 URL 中,我想提取 /a1/b1。
http://localhost:4200/root/a1/b1
下面是我的代码,
this.route.params.pipe(takeUntil(this.unsubscribe$)).subscribe(params => {
this.urlText = params.ID;
});
这只是给我/a1
【问题讨论】:
-
你可以试试这样的:
this.urlText = this.route.url.split("root")[1]; -
我收到此错误
Property 'split' does not exist on type 'Observable<UrlSegment[]>'.ts(2339) -
抱歉,我的意思是
this.router,其中router的类型是Router。 -
这似乎工作正常
标签: javascript angular typescript angular2-routing