Skip to content

Angular2 Router - canActivate is redirecting with post request #5

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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