A
A
Alexander2017-02-02 19:42:13
Angular
Alexander, 2017-02-02 19:42:13

Navigate feature not available in Route?

Angular 2*

import {Injectable} from '@angular/core';
import {Route, CanActivate} from '@angular/router';

@Injectable()
export class AuthGuard implements CanActivate {
    constructor(private router: Route) {
    }

    canActivate() {
        if (localStorage.getItem('currentUser')) {
            return true;
        }
        this.router.navigate(["/login"]);
        return false;
    }
}

The compiler complains:
ERROR in [at-loader] resources/assets/src/app/_guards/auth.guard.ts:13:21 
    Property 'navigate' does not exist on type 'Route'.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2017-02-02
@kentuck1213

Are you sure you need a Route and not a Router?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question