I'm using nested routes with react-router-dom v6. I would like to get hold of the path defined in a Route component within its element. Is there any other way than passing it as a prop to the element component itself?
Basically, how do I get / within Parent component even when I enter /subroute directly to the URL?
export default function App() {
return (
<Router>
<Routes>
<Route path="/" element={<Parent />}>
<Route path="subroute" element={<Child />} />
</Route>
</Routes>
</Router>
);
}
Please see a codesandbox below.