I am trying to implement tabs navigation using React router v6. To do so, I need the following rendering pattern:
- Render
<Tabs />and<TabPanelA />when URL is/tabsDemo/a - Render
<Tabs />and<TabPanelB />when URL is/tabsDemo/b
<Tabs /> is a navigation bar that allows users to navigate between tab panels A and B. It needs to be aware of currentTab so that it can change the corresponding tab's color. It also needs to be constantly rendered even as the user navigates across different tab panels.
However, my current code only renders <TabPanelA /> when the URL is /tabsDemo/a because /tabsDemo/a is more specific than /tabsDemo/:currentTab
function App() {
return (
<Routes>
<Route path="tabsDemo" element={<Outlet />}>
<Route path=":currentTab" element={<Tabs />} />
<Route path="a" element={<TabPanelA />} />
<Route path="b" element={<TabPanelB />} />
</Route>
</Routes>
);
}
How can I achieve the aforementioned rendering pattern?