Is it possible to match the # part of a route in React Router 4

前端 未结 3 1337
盖世英雄少女心
盖世英雄少女心 2021-02-20 04:04

In my app, I\'d like to match both the path and the hash to different components. For example:

/pageA#modalB

Would show PageA as the main page

3条回答
  •  情书的邮戳
    2021-02-20 04:29

    Not out of the box, but the beauty of React Router 4 is that it's incredibly easy to implement this yourself.

    let HashRoute = ({ component: Component, path, ...routeProps }) => (
      
          location.hash === path && 
        }
      />
    )
    
    
    

提交回复
热议问题