Attention
This article gets and modifies the URL with the ' http://172.16.0.88:8100/#/homePage?id=10&a=100 ' path as an example:
I. How to obtain a URL (do not modify the URL):
1. Get the current full URL path
var absurl = $location. Absurl ();
2. Gets the current URL path (the content after the current url#, including parameters and hash values):
var url = $location. URL ();
3. Gets the subpath of the current URL (that is, the content after the current url#, excluding parameters)
var pathurl = $location. Path ()
4. Get the protocol for the current URL (e.g. Http,https)
var protocol = $location. Protocol ();
5. Get Host Name
var localhost = $location. Host ();
6. Get the port of the current URL
var port = $location. Port ();
7. Gets the hash value of the current URL
var hash = $location. Hash ()
8. The serialized JSON object that gets the parameter of the current URL
var search = $location. Search ();
Two. Modify the URL of the relevant methods (change the URL related content):
1 Modify the subpath portion of the URL (that is, the content after the current url#, excluding parameters):
$location. URL ('/validation ');
2 Modify the hash value portion of the URL
$location. Hash (' Myhash3 ');
3 Modify the parameter portion of the URL (the first parameter represents the property name of the URL parameter, the second argument is the property value of the property name, or, if it is an existing property name, the new one)
$location. Search (' id ', ' a ')
//result (modify parameter value): Http://172.16.0.88:8100/#/homePage?id=111&a=100
$ Location.search (' IDs ', ' 111 ')
4. Modify multiple parameters at once
$location. Search ({ID: ' $ ', ' a ': ' 66 '})
5. The first value represents the property name of the URL parameter and, if it is an existing property name, deletes the property, if it is not already a property, it is not changed
Third, modify the URL but do not deposit history
In the above method of modifying the URL, each time the URL will be stored in the history, you can use the Back button to return to the modified URL, if you do not want this effect, but only to replace the current record, you can use$location.path('/validation').replace();
Summarize
The above is about ANGULARJS through the $location to get and change the current page URL of all the content, I hope this article on the content of everyone's study or work can bring certain help. If you have any questions, you can exchange messages.