Since in react-router-dom useHistory is no longer supported, I am looking for an equivalent to use history.location.pathname
            Asked
            
        
        
            Active
            
        
            Viewed 4,018 times
        
    7
            
            
         
    
    
        Fraction
        
- 11,668
- 5
- 28
- 48
 
    
    
        pratibimbam
        
- 91
- 1
- 5
- 
                    use this link https://stackoverflow.com/questions/63471931/using-history-with-react-router-dom-v6 – A.R.SEIF Dec 23 '21 at 10:57
- 
                    TL;DR Use [useNavigate](https://reactrouter.com/docs/en/v6/api#usenavigate). For other changes see the [v5 migration guide](https://reactrouter.com/docs/en/v6/upgrading/v5). – Drew Reese Dec 23 '21 at 11:04
1 Answers
13
            You have to use useLocation ¹, ² which returns a location object that contains the pathname and other information about the URL:
const location = useLocation();
console.log(location)
// {
//   pathname: "/invoices",
//   search: "?filter=sa",
//   hash: "",
//   state: null,
//   key: "ae4cz2j"
// }
 
    
    
        Fraction
        
- 11,668
- 5
- 28
- 48
- 
                    3This is exactly what I was looking for since useNavigate don't returns that location object. Thanks a lot. – pratibimbam Dec 23 '21 at 11:20