Javascript 如何将$location设置为$location.host

Javascript 如何将$location设置为$location.host,javascript,angularjs,angularjs-digest,Javascript,Angularjs,Angularjs Digest,所以$location.path是www.abc.com/portal,主机是www.abc.com 我正在尝试将位置设置为www.abc.com $location.path($location.host); 我认为在设置$location.path()之后,您必须使用$scope.$apply(),才能使其正常工作。,因为您需要重定向到主路由。因此,请尝试$location.path(“/”); 它在$location.host()之后添加字符串 例如: // suppose $locat

所以$location.path是www.abc.com/portal,主机是www.abc.com 我正在尝试将位置设置为www.abc.com

$location.path($location.host);

我认为在设置
$location.path()
之后,您必须使用$scope.$apply(),才能使其正常工作。

,因为您需要重定向到主路由。因此,请尝试$location.path(“/”); 它在$location.host()之后添加字符串

例如:

// suppose $location.host = 'www.abc.com'
$location.path('/example')
// redirect to 'www.abc.com/#/example'
$location.path('/')
// redirect to your "otherwise" [route][1] if '/' isn't define 'www.abc.com/#/'
请参阅此处的文档:

)

此方法是getter/setter

在没有任何参数的情况下调用时返回当前URL的路径

使用参数调用时更改路径并返回$location

注意:路径应始终以正斜杠(/)开头,此方法 如果缺少正斜杠,将添加正斜杠


我试图将整个url从www.abc.com/portal更改为www.abc.com

$location.path($location.host);
它与

$location.href=location.origin

因为location.host仅包含

www.abc.com

$location.path($location.host);
这将与

www.abc.com/portal/www.abc.com

$location.path($location.host);
使用我得到的location.origin

https://www.abc.com

$location.path($location.host);
所以它现在正在重定向