未处理的拒绝(TypeError):history.pushState 不是一个函数
2021-02-24
3585
useEffect(() => {
const generateToken = async() => {
try {
const token = await commerce.checkout.generateToken(cart.id, {
type: 'cart'
});
setCheckoutToken(token);
} catch (error) {
history.pushState('/');
}
}
generateToken();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cart]);
我第一次学习 React,在使用
history.pushState()
函数时遇到错误。我该如何最好地解决这个问题?
1个回答
应该只是
history.push('/');
useEffect(() => {
const generateToken = async() => {
try {
const token = await commerce.checkout.generateToken(cart.id, {
type: 'cart'
});
setCheckoutToken(token);
} catch (error) {
history.push('/');
}
}
generateToken();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cart]);
Sayog
2021-02-24