Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a built-in way to get the current URL without any query parameters?

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)?

like image 957
Jer Avatar asked May 06 '14 22:05

Jer


People also ask

Which method of $location service is used to get the current URL without any parameters?

path([path]); This method is getter / setter. Return path of current URL when called without any parameter.

How do I get the current URL in HTML?

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.

Which is the recommended way to prevent URL query parameters?

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.


1 Answers

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] 
like image 105
Jamy Avatar answered Sep 23 '22 12:09

Jamy