如何使角度路由器隐藏URL,并在刷新后留在同一页面上?

时间:2019-03-22 03:40:30

标签: angular typescript

我正在使用导航键切换页面,并在按“ 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页并刷新时,它只是以某种方式导航到我的索引页。

0 个答案:

没有答案