Netanel Basal

As part of the new standalone feature, Angular v14.2.0-rc.0 introduces a new method to use the Router API that doesn’t require using RouterModule.

Using the RouterModule, we pass extra options through a config object, for example:

We can now use these options by using feature functions:

The significant benefit of using this approach is that these features are now tree-shakable.

In tests, we can use the provideRouterForTesting() function as follows:

Follow me on Medium or Twitter to read more about Angular and JS!

--

--

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!

--

--

Netanel Basal

Netanel Basal

A FrontEnd Tech Lead, blogger, and open source maintainer. The founder of ngneat, husband and father.