I was able to solve this issue using useNavigate
let params = useParams();
let navigate = useNavigate();
const dispatch = useDispatch();
const productId = params.id;
const [qty, setQty] = useState(1);
const productDetails = useSelector((state) => state.productDetails);
const { loading, error, product } = productDetails;
useEffect(() => {
dispatch(detailsProduct(productId));
}, [dispatch, productId]);
const addToCartHandler = () => {
navigate(`/cart/${productId}?qty=${qty}`);
};
but the page didn't show anything
thank you
While you are using react functional componenets.you should use hooks
import {useHistory} from 'react-router-dom'
const App=()=>{
const history=useHistory()
const submit=()=>{
history.push("/products/23")
}
}
for react router v6
import {useNavigate} from 'react-router-dom'
const App=()=>{
const navigate=useNavigate()
const submit=()=>{
navigate("/products/23")
}
}