Problem and Solutions
How to use useLocation hook of in React Router DOM v6 ?
By M.K. Verma · 2 May 2022

First you have to import the useLocation hook
import { useLocation } from "react-router-dom";
then set
const location = useLocation();
now you can use the location object which has the following properties: key, pathname, search, hash, state
{
key: 'ac3df4', // not with HashHistory!
pathname: '/somewhere',
search: '?some=search-string',
hash: '#howdy',
state: undefined
}