react-router render menu when path does not match

后端 未结 6 1728
一向
一向 2020-12-20 11:36

I\'m using react-router and I want to render a menu component when the user is not in the root and not in the /login path. This is what I have so far

6条回答
  •  自闭症患者
    2020-12-20 11:57

    You can use useRouteMatch hook

    const ParentComponent = props => {
      const matched = useRouteMatch(['/', '/login'])
      
      if (matched && matched.isExact) return null
    
      return 
    }
    

提交回复
热议问题