Angular 4 How to redirect page after logout?

Viewed 24167

I know this has been answered previously but I'm not satisfied with the answers given.

My problem is simple, the user want to logout.

If it's on a page that required to be login (set in auth.guard.ts with auth.service.ts) and the user logout I want him to be redirected to home.

However if he is on a safe page I don't want to redirected him.

I could use the AuthGuard but I don't want to reload the page, so no:

location.reload()

What's my option ?

3 Answers

Please find following redirection code hope it helps

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

  export class LogoutComponant {
    title = 'Logout';


constructor(

    private router: Router,

) {}

onLogout() {
    this.router.navigate(['/'])
}

}
Related