If my URL is http://www.something.com/foo/bar/index.html?color=yellow&animal=rat
, it seems as though:
$location.path()
will return foo/bar/index.html
$location.absUrl()
will return http://www.something.com/foo/bar/index.html?color=yellow&animal=rat
$location.url()
will return foo/bar/index.html?color=yellow&animal=rat
Is there any function which will return http://www.something.com/foo/bar/index.html
?
Or do I have to construct that myself with functions like protcol, host, port, etc. (or strip the query params off myself)?
path([path]); This method is getter / setter. Return path of current URL when called without any parameter.
Answer: Use the window. location. href Property location. href property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc. The following example will display the current url of the page on click of the button.
One way to remove query parameters from pages is through the View Settings. Under Admin > View Settings > Exclude Query Parameters, list the query parameters that you want to exclude from your page paths.
As far as I'm aware you have to construct it yourself. Not that you were asking how to construct it, but for those who are wondering:
var url = $location.absUrl().split('?')[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With