I'm new to React. I'm trying to pass a value through URL using react-router-dom. But unable to get the params getting
TypeError: Cannot read property 'params' of undefined.
I tried the solutions that already present but nothing help. What is the mistake I did? Can someone explain it to me? Thanks in advance.
Main Component:
function App() {
return (
<div className="App">
<Router>
<Switch>
<Route path="/edit/:id" component={Edit} exact={true}>
<Edit />
</Route>
</Switch>
</Router>
</div>
);
}
export default App;
Edit Component:
class Edit extends Component {
constructor(props) {
super(props);
this.state = {
id: this.props.match.params.id
};
}
render() {
return <h2>Edit Page</h2>;
}
}
export default Edit;
this.propsand check whether thematchkey exists in it or not?