Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular2 Router - canActivate is redirecting with post request #5

Open
rameshcharykotha opened this issue Nov 3, 2016 · 0 comments

Comments

@rameshcharykotha
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant