The following gets and modifys the URL to (http://172.16.0.88:8100/#/homePage?id=10&a=100) as an example
【1】Get (no URL modification)
//1. Get the current complete url pathvar absurl = $(); //http://172.16.0.88:8100/#/homePage?id=10&a=100 //2. Get the current url path (current url#The following content includes parameters and hash values):var url = $();// Result: /homePage?id=10&a=100//3. Get the subpath of the current url (that is, the current url#The following content does not include parameters) var pathUrl = $()//Result: /homePage//4. Get the current url protocol (such as http, https)var protocol = $(); //Result: http//5. Get the host namevar localhost = $(); //Result: 172.16.0.88//6. Get the port of the current urlvar port = $(); //Result: 8100//7. Get the hash value of the current urlvar hash = $() //Result: http://172.16.088//8. Get the serialized json object of the current url parametervar search = $(); //result:{id: “10”, a: “100”}
【2】Modify (change URL-related content)
//1 Modify the subpath part of the url (that is, the current url#The following content does not include parameters):$('/validation');//Result: http://172.16.0.88:8100/#/validation//2 Modify the hash value part of the url$(‘myhash3'); //Result: http://172.16.0.88:8100/#/homePage?id=10&a=100#myhash3//3 Modify the parameter part of the url (the first parameter represents the attribute name of the url parameter, and the second parameter is the attribute value of the attribute name. If it is an existing attribute name, modify it. If it is not an existing attribute, add it)$(‘id','111') // Result (modify parameter value): http://172.16.0.88:8100/#/homePage?id=111&a=100$(‘ids','111') // Results (new ids parameter): http://172.16.0.88:8100/#/homePage?id=111&a=100&ids=111//4. Modify multiple parameters at once$({id:'55','a':'66'}) //Result: http://172.16.0.88:8100/#/homePage?id=55&a=66#myhash3//5. The first value represents the attribute name of the url parameter. If it is an existing attribute name, delete the attribute. If it is not an existing attribute, it means that it has not been changed.$(‘age',null)
【Three】Modify the URL but do not store the history record
When modifying the url method above, every time it is modified, the url will be stored in the history record. You can use the back button to return to the url before the modification. If you do not want this effect, just replace the current record.