DEV Community

Discussion on: Create a Simple Breadcrumb in Angular

Collapse
 
lionchi profile image
lionchi

Why is the call to buildBreadCrumb called from the constructor and component lifecycle method? If you remove from the designer, then the breadcrumbs are not displayed? It’s not clear to everyone why this is happening.

Collapse
 
zhiyueyi profile image
Zhiyue Yi

The buildBreadCrumb in the constructor is the initial build for breadcrumb when the application is loaded.

The buildBreadCrumb in onInit is actually in a subscription to a router change. It means that the breadcrumb is always re-built when there is a router change. Because if some modules are lazy loaded, you wouldn't have their routes in the beginning.

Hope that clarifies :)