
Use Window.location.href to get the URL of the current page.
const currentURL = () => window.location.href;
// EXAMPLE
currentURL(); // 'https://www.google.com/'
Source
https://www.30secondsofcode.org/js/s/current-url