'Is angular RouterModule singleton throughout the app?
I'm new to Angular and studying Angular tutorial here. I got so confused with this code related to routing system in Angular:
const routes: Routes = [
{path: 'heroes', component: HeroesComponent}
];
@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [RouterModule]
})
export class AppRoutingModule { }
The code is form here: https://angular.io/tutorial/toh-pt5
I'm wondering how is this working.
I learned that imports means this module is gonna use modules in the import statement and the module will export those in exports list. So based on this, this class imports RouterModule which ran forRoot function, and exports another RouterModule.
But here, it seems like there's only one RouterModule object and RouterModule in both imports and exports list are the same one so that the one in exports list is also effected by forRoot() function. Is this right?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
