throw redirect()
throw redirect()
is about aborting a page from being rendered and redirecting to the user to another page instead. Usenavigate()
if you want to redirect after the page is already rendered. See Abort >throw redirect()
VSthrow render()
VSnavigate()
.
throw redirect()
makes temporary redirections (HTTP status code302
). For permanent redirections (HTTP status code301
), use theredirects
setting or pass a second argumentthrow redirect('/some-url', 301)
.
Common use cases:
- Authentication and authorization, see Tool Integration > Authentication > Login flow.
- Data fetching error handling, see API >
data()
hook > Error handling.
While it's most commonly used with guard()
or data()
you can use it with any hook.
For improved DX, consider using
throw render()
instead ofthrow redirect()
. See Abort >throw redirect()
VSthrow render()
VSnavigate()
.
If throw redirect()
doesn't work, see Abort > Debug and Abort > throw redirect()
VS throw render()
VS navigate()
.