Tab with React Router
Using React Router to create Tab links and tab panels controlled by the browser history, while maintaining keyboard navigation.
Components
Controlling the Tab state
To control the selected tab state, you can pass the selectedId
prop to TabProvider
. This prop allows you to synchronize the tab state with other state sources, such as the browser history.
const location = useLocation();
You can learn more about controlled state on the Component providers guide.
Rendering a single TabPanel
It's possible to render a single TabPanel
component and use the tabId
prop to control the selected tab.
<Outlet />