te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Property 'navigate' does not exist on type 'Router'. Did you mean 'navigate
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Property 'navigate' does not exist on type 'Router'. Did you mean 'navigate

programmeradmin3浏览0评论

I have no idea why, but it was suddenly stopped working... The import is correct but it cannot see navigate() method.. any ideas?
Every answer for this is about missing import but there is a correct import here. navigate() stopped working in every part of my code LOL it is only example here. Any ideas?

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';
    }

}

I have no idea why, but it was suddenly stopped working... The import is correct but it cannot see navigate() method.. any ideas?
Every answer for this is about missing import but there is a correct import here. navigate() stopped working in every part of my code LOL it is only example here. Any ideas?

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';
    }

}
Share Improve this question edited Sep 30, 2021 at 21:33 Guerric P 31.8k6 gold badges58 silver badges105 bronze badges asked Apr 15, 2019 at 4:34 Mateusz GebroskiMateusz Gebroski 1,3345 gold badges30 silver badges61 bronze badges 4
  • console log the URL. there might be an issue that url is not available. – TheParam Commented Apr 15, 2019 at 5:00
  • Console log the this.router too. It seems it may have been overriden somehow in the dependency injection or sth. – Apokralipsa Commented Apr 15, 2019 at 5:06
  • Any chances of context change of this .. try logging and check. – Sachin Gupta Commented Apr 15, 2019 at 5:19
  • what does it mean and how could it be overriden? – Mateusz Gebroski Commented Apr 15, 2019 at 9:04
Add a ment  | 

3 Answers 3

Reset to default 7

This is a Typescript issue. Logging as suggested in the ments won't help here because the problem is at pilation time.

Try (<any>this.router).navigate([`/${url}`]); and if that fixes your problem, then you probably have an issue with your dependencies versions. Create a new project from scratch and use the generated package.json to update your project's one.

This issue will be raised because of your imports with "@angular/router" like this:

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

Sometimes when the typescript automatically adds the "import {} from ''" it uses different modules. Let me explain with an example:

I wrote the following to add dependency.

    constructor(private router: Router){}

The typescript added:

    import {Router} from "express"

instead of:

    import { Router } from '@angular/router'

So the piler gave me the same error that you faced and rightly so. I change the first import statement to the second one and the error was resolved. Keep an eye on these automatic imports to verify.

发布评论

评论列表(0)

  1. 暂无评论