The Response interface of the Fetch API has a read-only flag, redirected
, which indicates whether or not the response was the result of a request that was redirected.
Does the axios library have a similar capability? The best I could find is maxRedirects
which sets the maximum number of redirects to follow. However, I am simply looking to determine if it happened or not (so I can handle redirects specially), not prevent it from happening.
You can get the redirect count:
const response = await axios.get('http://someurlthatredirects.com');
console.log(response.request._redirectable._redirectCount);