【发布时间】:2021-03-14 16:00:17
【问题描述】:
当 Produit 组件的路径是带有 id 时,我无法让 Axios 工作:
<Route exact path="/produit/:id" component={Product} />
但是没有 :id Axios 工作正常:
<Route exact path="/produit" component={Product} />
Axios 的 Produit 组件:
//for the moment I do not use id
const { id } = useParams();
//im doing a Get
const getAvisData = async () => {
try {
const result = await Axios.get(`api/avis?produit=1`).then(res => {
console.log(res);
setComments(res.data['hydra:member']);
setCountAvis(res.data['hydra:totalItems']);
}).catch(error => {
console.error(error);
});
} catch (error) {
console.error(error);
}
}
useEffect(() => {
getAvisData();
}, []);
【问题讨论】:
标签: reactjs routes axios router