Is there any method to get the URL without query string?

Solution 1:

Try this:

let path = window.location.href.split('?')[0]
console.log({path})

Solution 2:

Read about Window.location and the Location interface:

const urlPieces = [location.protocol, '//', location.host, location.pathname]
let url = urlPieces.join('')

console.log({urlPieces, url})

Solution 3:

location.toString().replace(location.search, "")

Solution 4:

var url = window.location.origin + window.location.pathname;

Solution 5:

If you also want to remove hash, try this one: window.location.href.split(/[?#]/)[0]