我试图让通过Router
的ActivatedRouter
域,但我不能让域。
有没有办法从他们那里得到一个域名?
您可以使用代码,在这里你可以找到一切相关的路由器,包括主机名,网址,则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": ""
}
window.location.href
另外,从角router
对象包含有关路由器/导航多的信息。
给试一下这下面的代码
创建区域类型的变量
public location: Location
this.location['_platformStrategy']._platformLocation.location.host