Replies: 2 comments 1 reply
-
|
is something like this helpful <Routes>
<Route path="/app/:id/:tabName?" element={<SomeComponent />}>
<Route path="base" element={<ShowBaseData />} />
<Route path="advanced" element={<AdvancedUse />} />
</Route>
</Routes>function SomeComponent() {
const { id, tabName } = useParams<{ id: string; tabName?: string }>()
const style = tabName === 'base' ? 'base' : 'normal'
return (
<>
<div className={style}>Header</div>
<Outlet />
</>
)
}``` |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Something like this should do what you're looking for: function App() {
return (
<BrowserRouter>
<Routes>
<Route path="app/:id/*" element={<ProxySomething />} />
</Routes>
</BrowserRouter>
);
}
function ProxySomething() {
const { pathname } = useLocation();
const {
params: { id, tab },
} = matchPath("/app/:id/:tab", pathname)!;
return <SomeComponent id={id!} tabName={tab!} />;
}
function SomeComponent(props: { id: string; tabName: string }) {
const { tabName } = props;
let style = "normal";
if (tabName == "base") {
style = "base";
}
return (
<>
<div className={style}>Headers</div>
<Routes>
<Route path="base" element={<>Base</>} />
<Route path="advanced" element={<>Advanced</>} />
</Routes>
</>
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently upgrading a large app from react-router 5 to 6, an dhave stumbled uppon a small problem that is bugging me like hell,
I have a main component that renders my entry routes, where I need to extract entity id, and a tabname, the tabname is used in the rendered element, however, the rendered element itself generates the final routes that includes the tabnames. Like the following two pieces of code.
So if I have an url of
/app/--some-id--/basethen I need to render the ShowBaseData, and still be able to do styling of the initial div,Basically I want info about the route segments, before I actually define the complete route
Or am I asking for something that is completely undoable?
Beta Was this translation helpful? Give feedback.
All reactions