How to nest routes in React Router v4?

后端 未结 6 1228
予麋鹿
予麋鹿 2020-12-01 05:39

Is there a way to nest routes in React Router v4?

This works:

  
    
6条回答
  •  天涯浪人
    2020-12-01 06:23

    Best pattern I have found so far.

    // main app
    
    // not setting a path prop, makes this always render

    I can just keep nesting this inside a component and everything works nice including hmr(If using webpack, dont forget to set output.publicPath to "/")

    // dashboard component
    
    // the same way as before, not setting a path prop // makes it render on every /dashboard/** request // longer path (with same root) than others first

提交回复
热议问题