As mentioned in the Window.location Cheat Sheet, JavaScript provides a number of properties and methods to work with the current URL. Among those, Window.location.href
provides the easiest way to get the current URL as a string.
代码实现
const currentURL = () => window.location.href;
currentURL(); // 'https://www.google.com/'