Answers for "react router dom current path"

3

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
1

react current path

//Add your component to router
<Router path="/" component={Navigation}  />
//Get your path
this.props.location.pathname
Posted by: Guest on April-26-2021
3

react router dom current path hook

import { useLocation } from 'react-router-dom'

// Location is, for example: http://localhost:3000/users/new

// Care! MyComponent must be inside Router to work
const MyComponent = () => {
	const location = useLocation()
    
    // location.pathname is '/users/new'
    return <span>Path is: {location.pathname}</span>
}

export default MyComponent
Posted by: Guest on June-12-2020

Code answers related to "react router dom current path"

Code answers related to "Javascript"

Browse Popular Code Answers by Language