$location.path(path) vs $location.url(url) in AngularJS

后端 未结 2 2065
时光取名叫无心
时光取名叫无心 2021-02-02 09:37

I\'ve seen these calls:

$location.url(\'/path/to/something/\' + id + \'/index\');

and

$location.path(\'/path/to/something/\' +         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-02 09:54

    $location.path returns the part of the URL after the slash NOT including search string parameters (after the question mark)

    $location.url returns the entire URL after the slash, including search string parameters.

    For example, let's say you have this URL

    http://example.com/#/some/path?foo=bar&baz=xoxo

    $location.url returns /some/path?foo=bar&baz=xoxo

    $location.path returns /some/path

    These two functions act as both setters and getters.

    Url is basically Path + search strings. In your case, there are no search parameters, so both of them will return the same thing.

提交回复
热议问题