React: Hide a Component on a specific Route

前端 未结 4 1113
走了就别回头了
走了就别回头了 2020-12-31 05:01

New to React:

I have a

Component that I want to hide only when the user visit a specific page.

The way I des

4条回答
  •  情书的邮戳
    2020-12-31 05:33

    Since React Router 5.1 there is the hook useLocation, which lets you easily access the current location.

    import { useLocation } from 'react-router-dom'
    
    function HeaderView() {
      let location = useLocation();
      console.log(location.pathname);
      return Path : {location.pathname}
    }
    

提交回复
热议问题