What's the recommended command, library or tool for making API calls within react-router? #13714
Unanswered
binarykitchen
asked this question in
Q&A
Replies: 2 comments
-
Do you perform these API calls in client or server loader? |
Beta Was this translation helpful? Give feedback.
0 replies
-
API calls are from the client side, within React effects, for example. Yes, I realised 302 was wrong. Express.js default |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all,
In short, I'm stuck with HTTP 302 redirects being ignored for unauthenticated users. In my case, I expect a redirect happening back to the login page within react-router.
Sounds like a basic question.
Yet, here is the longer version: when you pick Axios for example, fetch the user resource unauthenticated, it grabs the new location within the HTTP 302 header right-away and does another API call without my will (this within the react-route loader).
Axios shouldn't make a subsequent call. The new location should be passed over to react-router to change the page, in my example, back to the login page.
This makes me question Axios, whether it's suitable for react-router. I've researched, read the documentation, there is no mention of this use case. To me, it feels like Axios is too bloated and shouldn't do subsequent API calls automatically. Should I go back to the native
fetch
?How do you handle 302 redirects for unauthenticated users in react-router based apps? Is Axios still recommended?
Just starting a discussion. Thanks for all your inputs :)
Beta Was this translation helpful? Give feedback.
All reactions