react use params code example
Example 1: usehistory, uselocation
import { useHistory } from "react-router-dom";
function HomeButton() {
let history = useHistory();
function handleClick() {
history.push("/home");
}
return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}
Example 2: react router url params
import { Route, useParams } from "react-router-dom";
<Route path="/:id" children={<Child />} />
let { id } = useParams();
Example 3: use query params react
const query = new URLSearchParams(this.props.location.search);
const token = query.get('token')
console.log(token)