No restricted globals

前端 未结 6 726
梦毁少年i
梦毁少年i 2021-01-30 03:58

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

Sear         


        
6条回答
  •  无人共我
    2021-01-30 04:09

    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__, }

提交回复
热议问题