Nested Routes not rendering with React Router v4

后端 未结 1 522
长发绾君心
长发绾君心 2020-11-29 11:43

I am trying to group some of my routes together with React Router v4 to clean up some of my components. For now I just want to have my non logged in routes group together a

1条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 12:15

    The reason is very obvious. for your route in main.js, you have specified the Route path of Public component with exact exact path='/' and then in the Public component you are matching for the other Routes. So if the route path is /signup, at first the path is not exact so Public component is not rendered and hence no subRoutes will.

    Change your route configuration to the following

    main.js

    const Main = () => {
      return (
        
    ); }; export default Main

    public.js

    const Public = () => {
      return (
        
          
          
          
        
      );
    };
    

    Also when you are specifying the nested routes these should be relative to the parent Route, for instance if the parent route is /home and then in the child Route you wish to write /dashboard . It should be written like

    or even better

    0 讨论(0)
提交回复
热议问题