How can I change the last component of a url path?

前端 未结 7 852
一整个雨季
一整个雨季 2021-02-09 03:15
\"http://something.com:6688/remote/17/26/172\"

if I have the value 172 and I need to change the url to 175

\"http://something.com:6688/         


        
7条回答
  •  孤街浪徒
    2021-02-09 03:57

    Depends on what you want to do.

    Actually change browser URL:
    If you actually want to push the browser to another URL you'll have to use window.location = 'http://example.com/175'.

    Change browser URL hash
    If you just want to change the hash you can simply use window.location.hash.

    Re-use the URL on links or similar
    If you want to reference a URL in links or similar, look into George's answer.

提交回复
热议问题