Skip to main content
Big news! Interval has been acquired by Meter. Learn more →

ctx.redirect

Perform a redirect to another action, page, or external URL in the user's current browser window.

// To another action or page
await ctx.redirect({ route: "edit_user", params: { id: user.id } });

// To an external URL
await ctx.redirect({ url: "https://example.com" });

Requires one of route or url to be specified.

info

By default, ctx.redirect will add a new entry to the user's history stack. If performing an immediate redirect to another route, consider using the replace property to maintain expected user behavior.

params

Optional

Record<string, any>

Arbitrary key/value pairs to send as params to the redirected route.

replace

Optional

boolean

Whether to replace the current item in the history stack with the redirected route. Equivalent to using `replaceState`. Only applies when using `route`. Defaults to false.

route

Optional

string

Redirects to another route by its slug.

url

Optional

string

Redirects to the given URL.

Returns

null

Was this section useful?