I am facing an issue that is not reloading the same component. After doing google I found that I need to add onsameurlnavigation 'reload' in app-routing-module.ts file, But that is also not working
below is my app-routing-module.ts code
const routes: Routes = [
{ path: 'student', component: StudentDetailsComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes,{onSameUrlNavigation: 'reload'})],
exports: [RouterModule]
})
export class AppRoutingModule { }
Below is my router link
<a [routerLink]="['/student']">
Student
</a>
Please help me to resolve this same page loading issue
Please be noted that onSameUrlNavigation only executes guards and resolvers but does not reinitialize components.
You can use Events from the RouterModule like to handle your scenario::
constructor(private router: Router) {}
ngOnInit() {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
// do some logic again when same url is clicked
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With