make only accessible for Admin in Website with Angual

You have to use canActivate in your routes definition.

@NgModule({
  imports: [
    RouterModule.forRoot([
      {
        path: 'team/:id',
        component: TeamComponent,
        canActivate: [AuthGuard]
      }
    ])
  ],
})

You can create custom conditions as AuthGuard:

@Injectable()
export class AuthGuard implements CanActivate {

  constructor(
  ) {}

  canActivate() {
    if (somthing) {
      return true;
    } else {
      this.router.navigate(['/login']);
      return false;
    }
  }

Check the documentation https://angular.io/api/router/CanActivate

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top