AngularJS中的$ location.path(path)与$ location.url(url) [英] $location.path(path) vs $location.url(url) in AngularJS
问题描述
我看过这些电话:
$location.url('/path/to/something/' + id + '/index');
和
$location.path('/path/to/something/' + id + '/index');
似乎他们在做同样的事情.
从文档中我发现URL例如/path?a=b#hash
,并且路径是URL的一部分.
It seems they are doing the same thing.
From documentation I've found that URL is e.g. /path?a=b#hash
, and path is a part of URL.
在使用相同参数的情况下,使用哪个设置器有何区别($location.path
或$location.url
)?
Is there any difference which of these setters to use ($location.path
or $location.url
) in case of the same argument?
推荐答案
$location.path
返回斜线后的URL部分,其中不包括搜索字符串参数(问号之后)
$location.path
returns the part of the URL after the slash NOT including search string parameters (after the question mark)
$location.url
返回斜杠后的整个URL,包括搜索字符串参数.
$location.url
returns the entire URL after the slash, including search string parameters.
例如,假设您有此URL
For example, let's say you have this URL
http://example.com/#/some/path?foo=bar&baz = xoxo
$location.url
返回/some/path?foo=bar&baz=xoxo
$location.path
返回/some/path
这两个函数同时充当setters
和getters
.
These two functions act as both setters
and getters
.
Url
基本上是Path + search strings
.在您的情况下,没有搜索参数,因此它们都将返回相同的内容.
Url
is basically Path + search strings
. In your case, there are no search parameters, so both of them will return the same thing.
这篇关于AngularJS中的$ location.path(path)与$ location.url(url)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!