Skip to content

Angular2 Router - canActivate is redirecting with post request #5

@rameshcharykotha

Description

@rameshcharykotha

Implemented CanActivate to guard the routes, and navigating to /login if the user is not logged in, but i can see it is redirecting with POST request, which results to 404 error.

@Injectable()
export class AuthGuard implements CanActivate {

constructor(private router: Router) { }

canActivate() {
    console.log("canActivate : AuthGuard");
    if (localStorage.getItem('currentUser')) {
        // logged in so return true
        return true;
    }

    // not logged in so redirect to login page
    this.router.navigate(['/login']);
    return false;
}

}
http://stackoverflow.com/questions/40393609/angular2-router-canactivate-is-redirecting-with-post-request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions