Answer the question
In order to leave comments, you need to log in
How to set up a dynamic route in react?
Hello, I ran into such a problem:
There are static uri and there are also dynamic uri.
It is necessary to implement the transition to dynamic uri, but at the same time check the existence of uri data, since they are taken from the server and can change. They also have nesting and start with dynamics. The city prefix will be added in the future.
Dynamic URLs are stored in the Redux store.
I tried to add: <Route path="/:category" component={Category} />
but in this case, the transition to NotFound will not happen.
How can I implement this approach, thanks in advance
<Switch>
<Route path="/" component={Home} />
<Route path="/contact" component={Contact} />
< ???? Category ???? />
<Route component={NotFound} />
</Switch>
Answer the question
In order to leave comments, you need to log in
When you write `:category` both `/` and `/contact` fall under this route and you just don't get there. Try to put it in first place (but this is not accurate). I would recommend nesting dynamic parameters. Regarding dynamic loading, there is a good package - `react-loadable`, you may need it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question