this is Alex, i am new to react, while i was learning from the video, he was not using react v6, so i type this.props.history.push(‘/add-employee’); it won’t work. Can somebody help me with the navigation in react v6code. Thanks!
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
If you still want to use react-router-dom v6 (see advice at the end of the answer), you can use useNavigate hook to achieve this
then in your functional component instead of
this.props.history.push('/add-employee');
Some advice related to the tutorial that you are following
It is easier to use a function component instead, where the
useNavigate
hook can be called.Then, navigating to a new route can be done like so:
For this to work with class components, you would need to create a function component wrapper.