I want to implement somewhat a combination of nested routes and sidebar routes in a single route file. I want the components to render like this.
"/" --- Registration page
"/login" ---- Login Page
"/application" --- Application Page
"/dashboard" --- Dashboard page with Sidebar and Application components
"/dashboard/application" --- Dashboard page with Sidebar and Application components
"/dashboard/user" --- Dashboard page with Sidebar and User components
I have my routes setup like this
<Switch>
<Route path="/" component={withAuth(Registration)} />
<Route path="/login" component={withAuth(Login)} />
<Route path={'/dashboard'} component={withAuth(Dashboard)}/>
</Switch>
Inside the dashboard page I have implemented basically the sidebar example from react-router-dom website.
It is working fine, however i want to put all the routing in a single file.
Something like this
<Switch>
<Route path="/" component={withAuth(Registration)} />
<Route path="/login" component={withAuth(Login)} />
<Route path={'/dashboard'} component={withAuth(Dashboard)} children={[Sidebar, Application]}/>
<Route path="/dashboard/application" component={withAuth(Dashboard)} children={[Sidebar, Application]}/>
<Route path="/dashboard/user" component={withAuth(Dashboard)} children={[Sidebar, User]}/>
</Switch>
The above code is fictional code but it is to give an idea of what I'm trying to achieve. I tried solution from a similar question, but it didn't work for me.
How do i put all the routing in a single file and take care of sidebar routing and nested routing in react-router-dom v4/v5?
I have created a example code sandbox, Please try this example.