I am using the react-router-dom. I want to change the url/route from http://localhost:3000/city/post to http://localhost:3000/user/harry . Now how to do this in react.js .anyone can explain how to solve this problem?
Asked
Active
Viewed 41 times
-2
Programming Bugz
- 1
- 1
-
Change in response to what? Have you [read the documentation](https://reactrouter.com/docs/en/v6)? – Quentin May 31 '22 at 06:49
-
I don't know why this was closed as a duplicate, there's just simply not enough context to allow for this. Should have been closed as needing more details. – Drew Reese May 31 '22 at 17:01
2 Answers
0
i assume you are using func component so with hook like below you can navigate between page(v6):
...
import { useNavigate } from "react-router-dom";
...
const navigate = useNavigate();
...//on some event like click or etc:
navigate('/user/harry');
kingofday
- 392
- 2
- 11
0
You can use the useNavigate Hook to navigate.
const nav = useNavigate();
nav("/user/harry")
nav("/") navigates to root, in this case localhost:3000, and you can add routes after the /. You can also use nav("..") to navigate one step up, in this case from /city/post to /city
eskiltb
- 85
- 8