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 didnt show anything enter image description here
thenk 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")
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.