Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #current #route
ADD COMMENT
Topic
Name
4+8 =