Using the Angular Router API without RouterModule

Netanel Basal
Netanel Basal
Published in
Aug 17, 2022

--

As part of the new standalone feature, Angular v14.2.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!

--

--

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