Angular v14.1.0 added a new property named code to the NavigationCancel event. It contains a code that indicates why the navigation was canceled. The code is an enum with the following options:
NavigationCancellationCode.Redirect — A navigation failed because a guard returned a UrlTree to redirect.
NavigationCancellationCode.SupersededByNewNavigation — A navigation failed because more recent navigation started.
NavigationCancellationCode.NoDataFromResolver —A navigation failed because one of the resolvers completed without emitting a value.
NavigationCancellationCode.GuardRejected — A navigation failed because a guard returned false.
When navigation is canceled, we can determine the reason for the cancellation and perform different actions as needed:
Follow me on Medium or Twitter to read more about Angular and JS!
A new function named reflectComponentType() has been added to Angular v14.1.0 that returns the following metadata from a component:
This function has several uncommon uses. It can be used to create debugging tools or, for example, we can use the selector metadata to create custom elements based on existing components:
We can use it to create dynamic components based on a JSON file. The following thread contains additional use cases: