Answer the question
In order to leave comments, you need to log in
How to create dynamic routes?
Hello everyone, I'm using react-router 3 version. An array of objects arrives from the back, each object has an ID, etc.
Using map, I go through the array in the List component and create a list. Now the question is how to create dynamic routes for a single list item?
<Route path="/notifications/list">
<IndexRoute component={withTraceLogging(Notifications)} />
<Route path='/notifications/:typeId' component={NotificationListItems} />
</Route>
Answer the question
In order to leave comments, you need to log in
You need to create two routes:
For spsis:
<Route path='/notifications' component={NotificationsList} />
<Route path='/notifications/:typeId' component={ConcreteNotification} />
const { typeId } = useParams()
useEffect(() => fetchNotification(typeId), [])
const notification = useSelector(s => s.notifications.data.find(n => n.typeId === typeId))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question