get url without query string
window.location.href.split('?')[0]
javascript: get the url without query string
let path = window.location.href.split('?')[0] console.log({path}) // { // "path": "https://stacksnippets.net/js" // } //or location.href.replace(location.search, '')
Source: stackoverflow.com