window.location.href adding link to an existing hostname instead of replacing it

I have a POST API function which activates on a button click. The API returns a generated link in a string format (‘data’ variable), but when I try to put in in window.location.href = data, the link is not replacing an actual href, but just glues it after the hostname. So basically, I get redirected… Read More window.location.href adding link to an existing hostname instead of replacing it

Cut protocol, host and port from window.location.href

Is there a way to cut protocol, host and port from window.location.href? Right now I have only this option. const windowUrlPattern = () => { let windowUrl; if (window.location.search.length !== 0 && window.location.hash.length === 0) { windowUrl = `${window.location.pathname}/${window.location.search}`; } else if (window.location.search.length !== 0 && window.location.hash.length !== 0) { windowUrl = `${window.location.pathname}/${window.location.search}${window.location.hash}`; } else… Read More Cut protocol, host and port from window.location.href

Cut protocol, host and port from window.location.href

Is there a way to cut protocol, host and port from window.location.href? Right now I have only this option. const windowUrlPattern = () => { let windowUrl; if (window.location.search.length !== 0 && window.location.hash.length === 0) { windowUrl = `${window.location.pathname}/${window.location.search}`; } else if (window.location.search.length !== 0 && window.location.hash.length !== 0) { windowUrl = `${window.location.pathname}/${window.location.search}${window.location.hash}`; } else… Read More Cut protocol, host and port from window.location.href