我正在使用导航键切换页面,并在按“ F5”刷新页面后尝试保留同一页面:
routing.ts:
const routes: Routes = [
{ path: '', redirectTo: '/gh', pathMatch: 'full' },
{ path: 'gh', component: MainPageComponent },
{ path: 'room', component: ChildRoomComponent },
{ path: 'room_detail', component: ChildRoomDetailComponent },
{ path: 'room_detail/:id', component: ChildRoomDetailComponent },
];
第1页:
linkToDetail(data: Room) {
this.router.navigate(['/room_detail', data.id], { skipLocationChange: true });
}
第2页:
constructor(
private api: ApiService,
private router: Router,
private route: ActivatedRoute
) {}
ngOnInit() {
this.roomId = this.route.snapshot.params.id;
this.router.navigate(['room_detail', this.roomId]);
}
当第1页切换到第2页并刷新时,它只是以某种方式导航到我的索引页。