|
246 | 246 | "Route definitions": {
|
247 | 247 | "prefix": "a-routes",
|
248 | 248 | "description": "Route definitions",
|
249 |
| - "body": [ |
250 |
| - "import { Routes } from '@angular/router';", |
251 |
| - "", |
252 |
| - "export const routes: Routes = [${0}]" |
253 |
| - ] |
| 249 | + "body": ["import { Routes } from '@angular/router';", "", "export const routes: Routes = [${0}]"] |
254 | 250 | },
|
255 | 251 | "Angular Module": {
|
256 | 252 | "prefix": "a-module",
|
|
286 | 282 | "prefix": "a-guard-can-activate",
|
287 | 283 | "description": "Angular CanActivate guard",
|
288 | 284 | "body": [
|
289 |
| - "import { Injectable } from '@angular/core';", |
290 |
| - "import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';", |
| 285 | + "import { inject } from '@angular/core';", |
| 286 | + "import { ActivatedRouteSnapshot, CanActivateFn, RouterStateSnapshot } from '@angular/router';", |
291 | 287 | "",
|
292 |
| - "@Injectable({providedIn: ${1:'root'}})", |
293 |
| - "export class ${2:Name}Guard implements CanActivate {", |
294 |
| - "\tconstructor() { }", |
| 288 | + "export const ${2:Name}Guard: CanActivateFn = (", |
| 289 | + "\troute: ActivatedRouteSnapshot,", |
| 290 | + "\tstate: RouterStateSnapshot", |
| 291 | + "\t) => {", |
295 | 292 | "",
|
296 |
| - "\tcanActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {", |
297 | 293 | "\t\treturn true;$0",
|
298 |
| - "\t}", |
299 | 294 | "}"
|
300 | 295 | ]
|
301 | 296 | },
|
302 | 297 | "Angular CanActivateChild Guard": {
|
303 | 298 | "prefix": "a-guard-can-activate-child",
|
304 | 299 | "description": "Angular CanActivateChild guard",
|
305 | 300 | "body": [
|
306 |
| - "import { Injectable } from '@angular/core';", |
307 |
| - "import { ActivatedRouteSnapshot, CanActivateChild, RouterStateSnapshot } from '@angular/router';", |
| 301 | + "import { inject } from '@angular/core';", |
| 302 | + "import { ActivatedRouteSnapshot, CanActivateChildFn, RouterStateSnapshot } from '@angular/router';", |
308 | 303 | "",
|
309 |
| - "@Injectable({providedIn: ${1:'root'}})", |
310 |
| - "export class ${2:Name}Guard implements CanActivateChild {", |
311 |
| - "\tconstructor() { }", |
| 304 | + "export const ${2:Name}Guard: CanActivateChildFn = (", |
| 305 | + "\troute: ActivatedRouteSnapshot,", |
| 306 | + "\tstate: RouterStateSnapshot", |
| 307 | + "\t) => {", |
312 | 308 | "",
|
313 |
| - "\tcanActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {", |
314 | 309 | "\t\treturn true;$0",
|
315 |
| - "\t}", |
316 | 310 | "}"
|
317 | 311 | ]
|
318 | 312 | },
|
319 |
| - "Angular CanLoad Guard": { |
320 |
| - "prefix": "a-guard-can-load", |
321 |
| - "description": "Angular CanLoad guard", |
| 313 | + "Angular CanMatch Guard": { |
| 314 | + "prefix": "a-guard-can-match", |
| 315 | + "description": "Angular CanMatch guard", |
322 | 316 | "body": [
|
323 |
| - "import { Injectable } from '@angular/core';", |
324 |
| - "import { CanLoad, Route } from '@angular/router';", |
| 317 | + "import { inject } from '@angular/core';", |
| 318 | + "import { CanMatchFn, Route, Router, UrlSegment } from '@angular/router';", |
325 | 319 | "",
|
326 |
| - "@Injectable({providedIn: ${1:'root'}})", |
327 |
| - "export class ${2:Name}Guard implements CanLoad {", |
328 |
| - "\tconstructor() { }", |
329 |
| - "", |
330 |
| - "\tcanLoad(route: Route) {", |
331 |
| - "\t\treturn true;$0", |
332 |
| - "\t}", |
| 320 | + "export const ${2:Name}Guard: CanMatchFn = (", |
| 321 | + "\troute: Route,", |
| 322 | + "\tsegments: UrlSegment[]", |
| 323 | + ") => {", |
| 324 | + "\treturn true;$0", |
333 | 325 | "}"
|
334 | 326 | ]
|
335 | 327 | },
|
336 | 328 | "Angular CanDeactivate Guard": {
|
337 | 329 | "prefix": "a-guard-can-deactivate",
|
338 | 330 | "description": "Angular CanDeactivate guard",
|
339 | 331 | "body": [
|
340 |
| - "import { Injectable } from '@angular/core';", |
341 |
| - "import { ActivatedRouteSnapshot, CanDeactivate, RouterStateSnapshot } from '@angular/router';", |
| 332 | + "import { inject } from '@angular/core';", |
| 333 | + "import { CanDeactivateFn } from '@angular/router';", |
342 | 334 | "import { Observable } from 'rxjs';",
|
343 | 335 | "",
|
344 |
| - "import { ${2:ComponentName}Component } from './${3:filename}.component';", |
345 |
| - "", |
346 | 336 | "// Consider using this interface for all CanDeactivate guards,",
|
347 | 337 | "// and have your components implement this interface, too.",
|
348 | 338 | "//",
|
349 |
| - "// e.g. export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {", |
| 339 | + "// e.g. export class VillainsComponent implements CanComponentDeactivate { ...", |
350 | 340 | "//",
|
351 |
| - "// export interface CanComponentDeactivate {", |
352 |
| - "// canDeactivate: () => any;", |
353 |
| - "// }", |
354 |
| - "", |
355 |
| - "@Injectable({providedIn: ${4:'root'}})", |
356 |
| - "export class ${1:Name}Guard implements CanDeactivate<${2:ComponentName}Component> {", |
357 |
| - "\tcanDeactivate(", |
358 |
| - "\t\tcomponent: ${2:ComponentName}Component,", |
359 |
| - "\t\tcurrentRoute: ActivatedRouteSnapshot, ", |
360 |
| - "\t\tcurrentState: RouterStateSnapshot", |
361 |
| - "\t): Observable<boolean>|Promise<boolean>|boolean {", |
362 |
| - "\t\treturn false;$0", |
| 341 | + "export interface CanComponentDeactivate {", |
| 342 | + "\tcanDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;", |
| 343 | + "}", |
| 344 | + "", |
| 345 | + "export const ${1:Name}Guard: CanDeactivateFn<CanComponentDeactivate> = (", |
| 346 | + "\tcomponent: CanComponentDeactivate", |
| 347 | + ") => {", |
| 348 | + "\t\tif (component.canDeactivate()) {", |
| 349 | + "\t\t\tconsole.log(`💂♀️ [Guard] - Can Deactivate Guard - allowed`);", |
| 350 | + "\t\t\treturn true;", |
| 351 | + "\t\t} else {", |
| 352 | + "\t\t\tconsole.log(`💂♀️ [Guard] - Can Deactivate Guard - not allowed`);", |
| 353 | + "\t\t\treturn false;", |
363 | 354 | "\t}",
|
364 | 355 | "}"
|
365 | 356 | ]
|
|
380 | 371 | ]
|
381 | 372 | },
|
382 | 373 | "Angular Network-Aware Preload Strategy": {
|
383 |
| - "prefix": "a-preload-network-strategy", |
| 374 | + "prefix": "a-preload-network-strategy", |
384 | 375 | "description": "Angular network aware preload strategy",
|
385 | 376 | "body": [
|
386 | 377 | "import { Injectable } from '@angular/core';",
|
|
0 commit comments