我的完整URL是
/settings/logs#/extra
但是window.location.pathname
刚刚返回
/settings/logs
在浏览器中,如何获取包括#
和其后信息的完整路径?
window.location.href
获取完整的url(带有协议,主机等),或者将window.location.pathname
与window.location.hash
并置。console.log(window.location.href); // Result: https://www.google.com/path/#hash
console.log(window.location.pathname + window.location.hash); // Result: /path/#hash
请参见Location API
window.location.href
有关更多信息:https://www.w3docs.com/snippets/javascript/how-to-get-current-url-in-javascript.html