My app.component.html
is very light
<div class="landing-page">
<div class="main">
<router-outlet></router-outlet>
<div class="footer">
<div class="logo-wrapper">
<a routerLink="/"><img src="assets/images/logo.png" srcset="assets/images/logo@2x.png 2x,assets/images/logo@3x.png 3x" /></a>
</div>
</div>
</div>
</div>
I have a the following routes defined in AppRoutingModule
:
const routes: Routes = [
{ path: 'book/:id', component: BookComponent },
{ path: '**', component: LandingPageComponent }
];
in my LandingPageComponent
I'm navigating to the book
like this:
constructor(private router: Router) {
}
OpenBookComponent(id){
this.router.navigate(["/book", id], {skipLocationChange: true});
}
Up to this point everything works perfect.
The problem start when returning to the main page by navigating to ["/"]
Both clicking back <
in the browser or programmatically trying to navigate from BookComponent
to the base link, reveal the full path in the address bar (i.e.: http://localhost:4200/book/123
) and results in displaying only the footer
my code navigating back in BookComponent
is:
constructor(private route: ActivatedRoute, private router: Router) {
}
ngOnInit() {
this.id = this.route.snapshot.paramMap.get('id');
}
closeBook(){
this.router.navigate(["/"], {skipLocationChange: true});
}
How can I clear all parameters from the address when going back, so it remains just /
or http://localhost:4200
?