我想从 url 中获取 id
http://localhost:4200/courses/5a0eb3d7f6b50c2589c34e57所以在我的 app.module.ts 我有这样的路线
{路径:'课程/:id',组件:课程组件,canActivate:[AuthGuard]}在我的 course.component.ts 中,我有以下代码:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-course',
templateUrl: './course.component.html',
styleUrls: ['./course.component.css']
})
export class CourseComponent implements OnInit {
id: String;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.id = this.route.snapshot.queryParams["id"];
console.log(this.id)
}
}