属性 'navigate' 在类型 'Router' 上不存在。您是说 'navigated' 吗?

Property 'navigate' does not exist on type 'Router'. Did you mean 'navigated'?

我不知道为什么,但它突然停止工作了……import 是正确的,但它看不到 navigate() 方法。有什么想法吗?
每个答案都是关于缺少 import 但这里有一个正确的 importnavigate() 在我的代码的每个部分都停止了工作大声笑这只是这里的例子。有什么想法吗?

import { Injectable } from '@angular/core';

import { Actions, Effect, ofType } from '@ngrx/effects';
import * as  AuthActions from './auth.actions'
import * as UserDetailsActions from '../user/user-store/user.actions';
import * as StudentActions from '../../student/student-store/student.actions';

import { map, mergeMap, switchMap, switchMapTo, concatMapTo, withLatestFrom } from 'rxjs/operators';

import { Router } from '@angular/router';

@Injectable()
export class AuthEffects {
    constructor(private actions$: Actions,
                private router: Router) { }

    @Effect()
    authSignin = this.actions$
        .pipe(
            ofType(AuthActions.TRY_SIGNIN),
            map((action: AuthActions.TrySignin) => {
                return action.payload;
            }),
            switchMap((authData: any) => {

                //here should be request to backend server with JWT
                //set token and and username or user id
                const userRetunedFromRequest = {
                    id: '5',
                    username: authData.username,
                    role: authData.role
                }

                localStorage.setItem('currentUser', JSON.stringify(userRetunedFromRequest));
                //----------------------------------------------------

                return [
                    new AuthActions.SigninUser,
                    new UserDetailsActions.GetUserDetailsById
                ]
            })
        );

    @Effect({ dispatch: false })
    loginRedirect = this.actions$
        .pipe(
            ofType(AuthActions.SIGNIN_USER),
            map((action: AuthActions.SigninUser) => {
                let url = this.navigateByUserRole();
                this.router.navigate([`/${url}`]);
            })
        );


    private navigateByUserRole(): string {
        return JSON.parse(localStorage.getItem('currentUser')).role === 'PARENT' ? 'student' : 'teacher';
    }

}

这是打字稿问题。按照评论中的建议进行日志记录在这里无济于事,因为问题出在编译时。

尝试 (<any>this.router).navigate([`/${url}`]); 如果这解决了您的问题,那么您的依赖项版本可能有问题。从头开始创建一个新项目并使用生成的 package.json 更新您的项目。