I have Routes
branchiing like this below
const App = () => {
return (
<BrowserRouter>
<Routes>
<Route path={`/`} element={<TopPage />} />
<Route path={`/dev`} element={<TopPage />} />
Now I want to do some task depending on url like this below.
(This code is wrong, but I hope it can explain what I want to do)
const App = () => {
return (
<BrowserRouter>
<Routes>
<Route path={`/`} dothis={var variable="prod";render(<TopPage>) />
<Route path={`/dev`} dothis={var variable="dev";render(<TopPage>)/>
Is there any way to do this?
2
Answers
You should useEffect or useMemo (or you could just write code in your component inline for the useMemo case) depending on your use case.
Looks like you’re wanting props
Then in your
TopPage
componentIf you’re using TypeScript, you should look into using an enum or union to prevent making typos in the name or forgetting the possible valid values.