Answers for "use route to get current url react router dom"

6

react get current route

/*In the 5.1 release of react-router there is a hook called useLocation,
which returns the current location object. 
This might be useful any time you need to know the current URL.*/
import { useLocation } from 'react-router-dom';

const location = useLocation();
console.log(location.pathname);
Posted by: Guest on December-24-2020
3

How to get current URL with Javascript or React

const currentURL = window.location.href // returns the absolute URL of a page

const pathname = window.location.pathname //returns the current url minus the domain name
Posted by: Guest on October-13-2021

Code answers related to "use route to get current url react router dom"

Code answers related to "Javascript"

Browse Popular Code Answers by Language