Whenever I switch routes in my Angular application, such as going from home
to settings
and back to home
, all the variables seem to be duplicated from the home
page and are never destroyed.
I noticed that I created a loop in the home
component that displays a timestamp. Each time I perform the mentioned test case, the timer keeps printing more and more information.
Is there a way to prevent this unwanted behavior?
interface-routing.module.ts
const routes: Routes = [
{
path: '',
component: InterfaceComponent,
children: [
{
path: 'home', component: HomeComponent
},
{
path: 'settings', component: SettingsComponent
},
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
}
]
},
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
}
];