无法从 Angular2 中的动态 url 获取参数

Not able to get the parameters from the dynamic url in Angular2

我正在尝试在 URL 中使用参数 event_id 的名为 'event' 的路由。

app 路由模块有这个

{ path: 'event/:event_id', component: EventComponent },

组件尝试使用 Activated 路由从 url 获取 event_id。

import { ActivatedRoute, Params } from '@angular/router';
export class EventComponent implements OnInit {
  event: JSON;
  id: String;
  constructor(private route: ActivatedRoute) {
  }
  ngOnInit() {
    this.route.queryParams.subscribe(params => {
      console.log('that kind of madness can\'t be undone');
      console.log(params['event_id']); // checking result
    })
  }

console.log(params['event_id']) 结果给出了一个空对象。

:eventId 不是查询参数,它属于路由参数,所以检查 params Observable on current activate route.

this.route.params.subscribe(params => {
  console.log('that kind of madness can\'t be undone');
  console.log(params['event_id']); // checking result
})