如何在角7路由器送域名

问题描述 投票:-1回答:2

我试图让通过RouterActivatedRouter域,但我不能让域。

有没有办法从他们那里得到一个域名?

angular
2个回答
0
投票

您可以使用代码,在这里你可以找到一切相关的路由器,包括主机名,网址,则params等得到充分Location对象 -

constructor(@Inject(DOCUMENT) private document) {
   console.log(document.location);
}

该对象包含信息 -

{
  "href": "http://localhost:4200/",
  "ancestorOrigins": {},
  "origin": "http://localhost:4200",
  "protocol": "http:",
  "host": "localhost:4200",
  "hostname": "localhost",
  "port": "4200",
  "pathname": "/",
  "search": "",
  "hash": ""
}

Alternate -

window.location.href

另外,从角router对象包含有关路由器/导航多的信息。


1
投票

给试一下这下面的代码

创建区域类型的变量

public location: Location
this.location['_platformStrategy']._platformLocation.location.host
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.