React Router: how to get the redirect Response
of a redirect call? when returned/thrown from loader?
#11715
svenvandescheur
started this conversation in
Proposals
Replies: 3 comments 6 replies
-
Remix doesn't give you direct access to the response. If you need access to the redirect reason, then you can include it in the search params. async function authenticatedPageLoader() {
// Some auth check fails...
return redirect("/login?reason=Please log in!");
}
// This one receives `Params` and a `Request` without any information about the reason why the redirect happened which is passed to the `Response`.
async function loginLoader({params, request}) {
// Explain the user that they need to be logged in to visit "/some/authenticated/page"
const url = new URL(request.url)
const reason = url.searchParams.get('reason') ?? 'Unknown reason'
// ...
} |
Beta Was this translation helpful? Give feedback.
6 replies
-
I changed the category from Q&A to proposals as the requested feature does not seem to be available. I hacked on a bit on the I'm new to the codebase so I probably missed a lot of scenario's though... |
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
-
Scenario
redirect
with additional information passed to the theinit
parameter (ResponseInit
)Response
to explain the reason for the redirect to the user.Pseudo code
Questions
Response
object created by theredirect
call from a loader/Element of the target route?React Router
's built-ins?Beta Was this translation helpful? Give feedback.
All reactions