Redirect to another page for 301 response in API call
Unanswered
πΉπΎ_π·πππππππππππ π posted this in #help-forum
I have this function for API call which on 301 response needs to rediirect to another page without showing error or anything on the browser which is not working. I am able to redirect to another page which comes from the data.goto but doing that shows an error for few seconds and then only redirects. this is my code:
Did i do something wrong here?
This is the response for the 301 :
export const fetchAggregateCategoryTravelGuides = async ({
country,
category,
}: {
country: string;
category: string;
}) => {
const res = await fetch(
`${API_GET_TRAVEL_GUIDE_CATEGORY_AGGREGATE}/${country}/${category}`,
{
headers: getAppBasicAuthHeader(),
next: { revalidate: APP_ISR_REVALIDATE_SECONDS },
cache: "force-cache",
},
);
const data = await res.json();
if (data.status === 301) {
redirect(data.goto);
}
return data;
};Did i do something wrong here?
This is the response for the 301 :
{
"status": 301,
"message": "Moved Permanently",
"error": null,
"goto": "https://clothingshop/search/all-products"
}