Angular 路由器出错 "TS2339: Property 'navigate' does not exist on type 'Route'."

Angular router is giving error "TS2339: Property 'navigate' does not exist on type 'Route'."

我搞不懂这个。为什么导航不可用?
使用它会出现错误“TS2339:属性 'navigate' 在类型 'Route' 上不存在。”

https://angular.io/api/router/Router#navigate

这里是一个简单的例子: https://stackblitz.com/edit/angular-ivy-qpxiys?file=src/app/pages/testit/testit.component.ts

那是因为您在构造函数中使用 Route 而不是 Router

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-testit',
  templateUrl: './testit.component.html',
  styleUrls: ['./testit.component.css'],
})
export class TestitComponent implements OnInit {
  constructor(private router: Router) {} // < -- This was wrong.

  ngOnInit() {}

  changePage() {
    this.router.navigate(['your-desired-route-name']);
  }
}