The difference between $ location.path and $ location.url

What is the difference between $ location.path (redirecturl) and $ location.url (redirecturl)?

I am talking about setter methods for both, not getter methods

For me, $ location.url doesnt always take time to redirect, so I was thinking about using $ location.path, but I wanted to know the difference.

+4
source share
3 answers

The difference is in the recipient $location.url() and $location.path()

The url () URL returns the path, search, and hash of the form /path?search=a&b=c#hash , while path() returns only /path .

In terms of redirection, if this is just the way, then yes, I would use

 $location.path(redirectpath). 

You can learn more about $location docs

+5
source

Basically, path returns only the path, but the url also returns a possible search or other parameters.

Check out the examples from docs :

$ location.path

 // given url http://example.com/#/some/path?foo=bar&baz=xoxo var path = $location.path(); // => "/some/path" 

$ location.url

 // given url http://example.com/#/some/path?foo=bar&baz=xoxo var url = $location.url(); // => "/some/path?foo=bar&baz=xoxo" 
+5
source

path is only part of the url that does not include search and hash

See examples in $ location docs

0
source

All Articles