feat(router): allow throwing RedirectCommand to trigger redirects by atscott · Pull Request #69525 · angular/angular · GitHub
Skip to content

feat(router): allow throwing RedirectCommand to trigger redirects#69525

Draft
atscott wants to merge 1 commit into
angular:mainfrom
atscott:throwredirectcommand
Draft

feat(router): allow throwing RedirectCommand to trigger redirects#69525
atscott wants to merge 1 commit into
angular:mainfrom
atscott:throwredirectcommand

Conversation

@atscott

@atscott atscott commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This allows developers to throw a RedirectCommand directly from guards and resolvers to trigger a redirect.

The primary benefit is that we no longer need to pollute the return type of functions that redirect. For example, a deeply nested helper function or a resolver can now simply throw a RedirectCommand to short-circuit and redirect, instead of having to return the UrlTree or RedirectCommand all the way up the call stack.

This aligns with prior art in other modern framework routers (such as Next.js, Remix, and SvelteKit), which commonly use thrown exceptions or special redirect responses to abort execution and trigger immediate redirection.

This allows developers to throw a `RedirectCommand` directly from guards and resolvers to trigger a redirect.

The primary benefit is that we no longer need to pollute the return type of functions that redirect. For example, a deeply nested helper function or a resolver can now simply throw a `RedirectCommand` to short-circuit and redirect, instead of having to return the `UrlTree` or `RedirectCommand` all the way up the call stack.

This aligns with prior art in other modern framework routers (such as Next.js, Remix, and SvelteKit), which commonly use thrown exceptions or special redirect responses to abort execution and trigger immediate redirection.
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: router labels Jun 25, 2026
@ngbot ngbot Bot modified the milestone: Backlog Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: router detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant