Angularjs 在不重新加载页面的情况下更改url位置
例如,我有一些部分加载了一些URLAngularjs 在不重新加载页面的情况下更改url位置,angularjs,Angularjs,例如,我有一些部分加载了一些URL模板/test.html。此模板URL始终是相对的。我想在网站的不同位置使用相同的模板 所以,我想使用相同的相对urlhttp://somedomain.com/templates/Test.html即使我在http://somedaomian.com/some1/some2 我已尝试使用$loaction服务,但无法在需要时将$loaction设置回主页url 例如,在我的控制器中,我想: var new_base_url = homeURL(); func
模板/test.html
。此模板URL
始终是相对的。我想在网站的不同位置使用相同的模板
所以,我想使用相同的相对urlhttp://somedomain.com/templates/Test.html
即使我在http://somedaomian.com/some1/some2
我已尝试使用$loaction
服务,但无法在需要时将$loaction设置回主页
url
例如,在我的控制器中,我想:
var new_base_url = homeURL();
function homeUrl() {
/* Here is where I am unable to get the home url */
$location.path('/'); // simply returns the current url
};
如果需要绝对Url,
$location.absUrl()
将返回所有内容(所有Url段)
如果需要主机名,$location.host()
将返回主机名
如果需要协议,$location.protocol()
将返回该协议
如果需要路径,$location.path()
将返回该路径
如果需要散列,则$location.hash()
将返回该值
您应该能够使用这些方法解析出您要查找的url片段
var path = $location.path();
var hash = $location.hash();
var basePath = path.replace(hash, '');
谢谢,我希望有一个懒惰的方式。。。出于某种原因,
$loaction.path()
即使存在/something/something