Lastor
@Lastor
Wed, Aug 14, 2024 9:10 AM
Wed, Aug 14, 2024 9:11 AM
coding
好爛喔,瀏覽器的 js 好像沒有像 node 的 path.join 或 url.resolve 那類 API,可以自動幫你去組 url string,去判斷有沒有斜線
Lastor
@Lastor
Wed, Aug 14, 2024 9:11 AM
class URL 只能組 baseURL + path 的組合
Lastor
@Lastor
Wed, Aug 14, 2024 9:12 AM
如果是 host/path + path 這種去組,host 那邊給的 path 會被自動去掉
Lastor
@Lastor
Wed, Aug 14, 2024 9:12 AM
然後 new URL 出來的 instance,他的 pathname 不會自動幫你去算斜線
Lastor
@Lastor
Wed, Aug 14, 2024 9:14 AM
如果他本來紀錄的 pathname 屁股已經有斜線,再去加他不會幫你 handle 斜線......
/some/path/ + /path-a = /some/path//path-a
Lastor
@Lastor
Wed, Aug 14, 2024 9:14 AM
這樣難道得自己去做字串處理嗎.... 好煩啊~~~ (抱頭
WillieSmithChen
@williesmithchen
Wed, Aug 14, 2024 10:50 AM
urlJoin
載入新的回覆
/some/path/ + /path-a = /some/path//path-a