How to detect if variable has redirect #10755
-
React Router Dom V6I have two Loader functions which send req to server
I have a response handler from which I am managing all loader and action responses. Response Handler
And finally I have a loader
Now the problem is that when response handler returns redirect then loader is returning a object by assigning redirect object as a property of either permissions or userDetail instead of redirecting. Now in component function
My Question is : After extracting userDetail and permissions how can I detect if any one of them contains redirect object and if contains then just redirect it to where I have redirected from response handler. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
The return value of function isRedirect(response: Response) {
if (response.status < 300 || response.status > 399) return false;
if (!response.headers.has("location")) return false;
return true;
} |
Beta Was this translation helpful? Give feedback.
-
As @sergiodxa mentioned we can achive this in that way but I guess it is not a good Practice. |
Beta Was this translation helpful? Give feedback.
The return value of
redirect('/')
is a Response object, with a 3xx status code and a Location header, so you could do