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

前端 未结 7 851
一整个雨季
一整个雨季 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:58

    new URL("175", "http://something.com:6688/remote/17/26/172").href

    This also works with paths, e.g.

    new URL("../27", "http://something.com:6688/remote/17/26/172").href"http://something.com:6688/remote/17/27"

    new URL("175/1234", "http://something.com:6688/remote/17/26/172").href"http://something.com:6688/remote/17/26/175/1234"

    new URL("/local/", "http://something.com:6688/remote/17/26/172").href"http://something.com:6688/local/"

    See https://developer.mozilla.org/en-US/docs/Web/API/URL/URL for details.

提交回复
热议问题