Skip to content

How to detect if variable has redirect #10755

Closed Answered by sergiodxa
tirathsharma098 asked this question in Q&A
Discussion options

You must be logged in to vote

The return value of redirect('/') is a Response object, with a 3xx status code and a Location header, so you could do

function isRedirect(response: Response) {
  if (response.status < 300 || response.status > 399) return false;
  if (!response.headers.has("location")) return false;
  return true;
}

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@tirathsharma098
Comment options

Answer selected by tirathsharma098
Comment options

You must be logged in to vote
2 replies
@kiliman
Comment options

kiliman Aug 3, 2023
Collaborator

@tirathsharma098
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants