Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery remove option from select 
Javascript :: js string have number js 
Javascript :: get object key from value javascript 
Javascript :: add event listener in react useeffect 
Javascript :: javascript fill array from 0 to n 
Javascript :: javascript run command 
Javascript :: javascript get query parameter 
Javascript :: javascript get parent element height javascript 
Javascript :: javascript add class to element 
Javascript :: convert string in hh:mm am/pm to date js 
Javascript :: javascript read file lines into array vanilla 
Javascript :: javascript generate random numbers 
Javascript :: js remove the last character from a string 
Javascript :: javascript remove all children with class 
Javascript :: laravel data return in json 
Javascript :: js C:fakepath 
Javascript :: btoa is not defined js 
Javascript :: js get max value in an array 
Javascript :: javascript does not equal 
Javascript :: vite.config.js 
Javascript :: Removing Service Workers Programmatically 
Javascript :: route component with props 
Javascript :: safeareaview react native android 
Javascript :: generating random number in javascript 
Javascript :: jquery scroll to element id 
Javascript :: express response setTimeout 
Javascript :: using bootstrap in react 
Javascript :: how to remove spaces from strings javascript 
Javascript :: epsilon javascript 
Javascript :: add id attribute to jQuery steps 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =