I wonder how can I pass clicked item id to route path in React?
Here is my parent component
export default class ParentComponent extends Component {
state = {
data: null
};
render() {
return (
<section>
<Row>
<ul>
<li>....<li>
....
<ul>
</Row>
<Row>
<ChildComponent rowData={this.state.data} />
</Row>
</section>
);
}
}
I have a list element when I click to some of li element I get the id of this element. So far, everything is ok.
I wonder how and where I can pass the childComponent this item id like path parameter dynamically.
My id in this.state.data.id, and I want to create and pass this id to route of component
url will be like: details/id
So on click to li element route will go to child component and child component will have id of clicked item.
I'm using react-router
my route paths in my app.js:
<Switch>
<Route path="/login" />
<Route exact path="/callback" />
<Route path="/about" component={About} />
</Switch>