BeastCode / VSCode-Angular-TypeScript-Snippets

Visual Studio Code TypeScript snippets (TypeScript, Html, Angular Material, Flex Layout, ngRx, RxJS & Testing) for Angular 17
https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode
MIT License
92 stars 49 forks source link

Add Route Guard templates #23

Closed doggy8088 closed 7 years ago

doggy8088 commented 7 years ago

There are four different route guard types we can use to protect our routes:

If you providing these route guard templates will be very nice.

Thanks!

BeastCode commented 7 years ago

Great idea, thanks!

BeastCode commented 7 years ago

Do you have an example of what you think they should look like?

doggy8088 commented 7 years ago

You can reference the default template in the Angular CLI ng g guard command.

Here is a sample that generated from ng g guard login command. It's a CanActivate guard.

import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class LoginGuard implements CanActivate {
  canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
    return true;
  }
}
BeastCode commented 7 years ago

Thanks!!

BeastCode commented 7 years ago

Published in v4.2.1