【发布时间】:2017-10-26 16:43:23
【问题描述】:
路由操作不适用于组件和不同的参数。
我有一个获取不同参数的组件,如下所示。但是,当进入组件路由时,它只加载一次并且...
this.route.snapshot.params['id'] 未更新。
路线
export const ROUTES: Routes = [
{path: '', component: AppComponent,
children: [
{ path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: 'home', component: HomeComponent },
{ path: 'categoria/:id', component: ListaComponent },
{ path: 'player/:id', component: PlayerComponent }]
}]
组件
import {Component, OnInit } from '@angular/core';
import { PostServices } from '../postServices';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'net-lista',
templateUrl: './lista.component.html',
})
export class ListaComponent implements OnInit {
order: any;
constructor(private postServices: PostServices, private route: ActivatedRoute) {
}
ngOnInit() {
this.postServices.getPostByCategory(this.route.snapshot.params['id']).subscribe( (res) => {
this.order = res;
})
}
}
【问题讨论】: