-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Router Resolve<T> should have official support for UrlTree based redirection #29089
Comments
Agreed, this should be added as a feature. I'll assign to myself, but I know I won't be able to get to this until some time after version 8 is finalized (probably next month). If anyone in the community would like to pick this up, that would be great. It could be modeled on the changes we did to implement this feature in Guards (#26521 and #26478). |
Any news ? |
Returning an TL;DR: You can use We can either replace it with a proper ErrorHandler class provided via dependency injection, just like for the global ErrorHandler or, at least, we could provide the Router service instance to the router error handler function, not just the error, and it will allow you to do something like this: const ROUTER_CONFIG: ExtraOptions = {
errorHandler: (err: unknown, router: Router): any => {
if (err instanceof AccessDeniedError) {
router.navigateByUrl(PAGE_URL.ACCESS_DENIED);
} else if (err instanceof PageNotFoundError) {
router.navigateByUrl(PAGE_URL.PAGE_NOT_FOUND);
} else if (err instanceof HttpErrorResponse) {
// verify the response code and do something..
} else {
throw err;
}
}
}
@NgModule({
exports: [RouterModule],
imports: [RouterModule.forRoot(ROUTES, ROUTER_CONFIG)],
})
export class AppRoutingModule { } This last option would be very easy to implement, you just add
L.E. It looks like there is just one test for custom error handlers, which doesn't cover much And looking through the history (#25740) I found that the current L.E.2 It turns out that you can actually use export function appRoutingErrorHandler(this: Router, err: unknown): any {
// ...
}
const ROUTER_CONFIG: ExtraOptions = {
errorHandler: appRoutingErrorHandler,
} I think that this part should be documented, and maybe an example could be given. I'll look into this in the next week or so. |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
This would be possible after introducing a |
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Any update on that? |
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089
) Returning a `RedirectCommand` from a resolver can be interpreted as distinctly different from regular resolved data. When a resolver returns `RedirectCommand` we can interperet this as an intention to redirect in the same way as other guards. resolves angular#29089 PR Close angular#54556
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
馃殌 feature request
Relevant Package
@angular router
Description
I see that in the docs it is recommended to do the following to cancel a navigation event in a
Resolve<T>
route data resolver.While this does work it generates a pretty gnarly
NavigationCancel
event that basically says 'You broke my internal state':This is because we have overlapping navigation events, and the original navigation is cancelled because we essentially triggered the router's panic mode.
Describe the solution you'd like
Angular 7.1 introduced the option of returning a
UrlTree
from acanActivate
, and I think something similar should be added toResolve<T>
for feature parity.A
Resolve
may fail for many reasons, but we should have a clean option to redirect within the resolver - especially in cases where it is impossible to know the final destination until you've attempted to get the data.I think perhaps the signature of
resolve
needs to become something like :Describe alternatives you've considered
Yes, delving into the code showed me that I could throw an error that satisfies the
isNavigationCancelingError()
type-guard and not only would it give me a nicerNavigationCancel
event it would also allow me to pass aurl: UrlTree
parameter which will then be navigated to on my behalf.While this actually works quite well - and gives the following 'nice' event it isn't really supported since I have to use the magic internal property name - and also not every reason for aborting a Resolve is an error condition.
The other alternative is what is suggested in the docs, but the error (
Navigation ID 5 is not equal to the current navigation id 6
) from doing that just makes it look like something is broken.I think the mechanics of this are basically already there, expecially with the new functionality in 7.1 to handle a
UrlTree
. There is also plenty of need for such a feature on Stackoverflow..The text was updated successfully, but these errors were encountered: