I am using React and Redux to develop a webapp and when I started up my project I got this:
Line 13: Unexpected use of 'location' no-restricted-globals
Search for the keywords to learn more about each error.
I search a lot about how to resolve it, but none of the answers I found helped me, so I turned to Stack overflow.
Does anyone know how to fix this error? I appreciate all the help I can get.
Try adding window before location (i.e. window.location).
This is a simple and maybe not the best solution, but it works.
On the line above the line you get your error, paste this:
// eslint-disable-next-line no-restricted-globals
Use react-router-dom library.
From there, import useLocation hook if you're using functional components:
import { useLocation } from 'react-router-dom';
Then append it to a variable:
Const location = useLocation();
You can then use it normally:
location.pathname
P.S: the returned location object has five properties only:
{ hash: "", key: "", pathname: "/" search: "", state: undefined__, }