Why does Angular provide both
RouterModule.forRoot(routes) and RouterModule.forChild(routes)?- a
forRootis for standalone components andforChildis only for NgModules — a distinction that doesn't reflect howRouterModuleactually works in either API style. - bThey are interchangeable aliases kept for backward compatibility
- cIt provides the
Routerservice once at the root, whileforChildadds a feature module's routes to it.✓ - d
forChildis required only when using lazy loading, and has no effect otherwise
Explanation:
forRoot() is meant to be called once at the root, since it provides the Router and its configuration. forChild() only adds route definitions to the existing router without re-providing the service, which avoids duplicate router instances when feature modules import RouterModule.