如果我console.log(window.location)
我明白了:
Location {replace: function, assign: function, ancestorOrigins: DOMStringList, origin: "https://localhost:3000", hash: "#/account/content?hello=world"…}
ancestorOrigins: DOMStringList
assign: function () { [native code] }
hash: "#/account/content?hello=world"
host: "localhost:3000"
hostname: "localhost"
href: "https://localhost:3000/#/account/content?hello=world'"
origin: "https://localhost:3000"
pathname: "/"
port: "3000"
protocol: "https:"
reload: function reload() { [native code] }
replace: function () { [native code] }
search: ""
toString: function toString() { [native code] }
valueOf: function valueOf() { [native code] }
__proto__: Location
我希望search
为?hello=world
,但事实并非如此。
为什么?
我正在使用Chrome 35
答案 0 :(得分:19)
因为?hello=world
在您的情况下不被视为查询字符串
它是anchor
(#
)的一部分,可以使用
window.location.hash