How to redirect?
Answered
Siamese posted this in #help-forum
SiameseOP
useEffect(() => {
Promise.all([
axios.get(`/api/bot/guild?id=${id}`),
axios.get(`/api/db/guild?id=${id}`)
]).then(function (response: Array<any>) {
setData({
bot: response[0]?.data,
db: response[1]?.data
});
}).catch(error => {
if (error.response.status === 401) redirect(error.response.data.redirect);
});
}, [id]);this is my code, how can i fix the redirect? it gives some error with NEXT_REDIRECT and nothing more
Answered by joulev
use
router.push instead. redirect is not to be used in this kind of situation6 Replies
@Siamese
useEffect(() => {
Promise.all([
axios.get(`/api/bot/guild?id=${id}`),
axios.get(`/api/db/guild?id=${id}`)
]).then(function (response: Array<any>) {
setData({
bot: response[0]?.data,
db: response[1]?.data
});
}).catch(error => {
if (error.response.status === 401) redirect(error.response.data.redirect);
});
}, [id]);
this is my code, how can i fix the redirect? it gives some error with NEXT_REDIRECT and nothing more
use
router.push instead. redirect is not to be used in this kind of situationAnswer
@joulev use `router.push` instead. `redirect` is not to be used in this kind of situation
SiameseOP
any way to redirect directly on api route in this case?
would be easier to do it there rather than after fetch
@Siamese any way to redirect directly on api route in this case?
from api routes, no, impossible. if you use server action then yes
redirect works thereSiameseOP
aight
thanks