Nested routes with react router v4 / v5

后端 未结 11 1991
广开言路
广开言路 2020-11-22 12:34

I am currently struggling with nesting routes using react router v4.

The closest example was the route config in the React-Router v4 Documentation.

I want t

11条回答
  •  温柔的废话
    2020-11-22 13:30

    A complete answer for React Router v6 or version 6 just in case needed.

    import Dashboard from "./dashboard/Dashboard";
    import DashboardDefaultContent from "./dashboard/dashboard-default-content";
    import { Route, Routes } from "react-router";
    import { useRoutes } from "react-router-dom";
    
    /*Routes is used to be Switch*/
    const Router = () => {
    
      return (
        
          } />
          } />
          } />
          }>
            } />
            } />
            } />
            } />
          
          } />
        
      );
    };
    export default Router;
    
    import DashboardSidebarNavigation from "./dashboard-sidebar-navigation";
    import { Grid } from "@material-ui/core";
    import { Outlet } from "react-router";
    
    const Dashboard = () => {
      return (
        
          
          
        
      );
    };
    
    export default Dashboard;
    

    Github repo is here. https://github.com/webmasterdevlin/react-router-6-demo

提交回复
热议问题