gpt4 book ai didi

javascript - location.href 中的 URL 缺少 searchParams

转载 作者:行者123 更新时间:2023-12-02 22:45:01 25 4
gpt4 key购买 nike

我正在尝试解析当前路线的查询/搜索参数

let url = new URL(location.href);

当我查看url时,搜索参数位于href中。我期望它们位于 searchParams 中,它是空的。我的期望落空了吗?

网址:

hash: "#/admin?ac=flags"
host: "localhost:8084"
hostname: "localhost"
href: "http://localhost:8084/#/admin?ac=flags"
origin: "http://localhost:8084"
password: ""
pathname: "/"
port: "8084"
protocol: "http:"
search: ""
searchParams: URLSearchParams { }

最佳答案

href 包含整个 URL

查询字符串将出现在 searchParams 中,但您的网址没有查询字符串。

您有一个片段标识符(以 # 开头的部分),它是 URL 的最后一个组成部分。

如果您有一个查询字符串,则需要一个以 ? 开头的部分,位于路径之后,但位于片段标识符之前。

关于javascript - location.href 中的 URL 缺少 searchParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58439776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com