This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(router): Added content updates to developer guide
closes #1905 Added section for RouterLinkActive Added section for global query params and fragments Added section for RouterState Added wildcard route to example configuration Updated code samples Renamed .guard files to .service Renamed interfaces.ts to can-deactivate-guard.service.ts Removed unused files
- Loading branch information
1 parent
90836b7
commit 8c1193d
Showing
30 changed files
with
330 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...s/_examples/router/ts/app/auth.guard.1.ts → ...les/router/ts/app/auth-guard.service.1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
public/docs/_examples/router/ts/app/auth-guard.service.2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// #docregion | ||
import { Injectable } from '@angular/core'; | ||
import { CanActivate, Router, | ||
ActivatedRouteSnapshot, | ||
RouterStateSnapshot } from '@angular/router'; | ||
import { AuthService } from './auth.service'; | ||
|
||
@Injectable() | ||
export class AuthGuard implements CanActivate { | ||
constructor(private authService: AuthService, private router: Router) {} | ||
|
||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | ||
if (this.authService.isLoggedIn) { return true; } | ||
|
||
// Store the attempted URL for redirecting | ||
this.authService.redirectUrl = state.url; | ||
|
||
// Navigate to the login page | ||
this.router.navigate(['/login']); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// #docregion | ||
import { Injectable } from '@angular/core'; | ||
import { CanActivate, Router, | ||
ActivatedRouteSnapshot, | ||
RouterStateSnapshot } from '@angular/router'; | ||
import { AuthService } from './auth.service'; | ||
|
||
@Injectable() | ||
export class AuthGuard implements CanActivate { | ||
constructor(private authService: AuthService, private router: Router) {} | ||
|
||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | ||
if (this.authService.isLoggedIn) { return true; } | ||
|
||
// Store the attempted URL for redirecting | ||
this.authService.redirectUrl = state.url; | ||
|
||
// Create a dummy session id | ||
let sessionId = 123456789; | ||
|
||
// Set our navigation extras object | ||
// that contains our global query params and fragment | ||
let navigationExtras = { | ||
queryParams: { 'session_id': sessionId }, | ||
fragment: 'anchor' | ||
}; | ||
|
||
// Navigate to the login page with extras | ||
this.router.navigate(['/login'], navigationExtras); | ||
return false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ocs/_examples/router/ts/app/interfaces.ts → ...er/ts/app/can-deactivate-guard.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
public/docs/_examples/router/ts/app/crisis-center/crisis-admin.component.1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// #docregion | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
template: ` | ||
<h3>CRISIS ADMINISTRATION</h3> | ||
<p>Manage your crises here</p> | ||
`, | ||
directives: [] | ||
}) | ||
export class CrisisAdminComponent { } |
32 changes: 28 additions & 4 deletions
32
public/docs/_examples/router/ts/app/crisis-center/crisis-admin.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
// #docregion | ||
import { Component } from '@angular/core'; | ||
import { ROUTER_DIRECTIVES } from '@angular/router'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
@Component({ | ||
template: ` | ||
<h3>CRISIS ADMINISTRATION</h3> | ||
<p>Manage your crises here</p> | ||
<p>Session ID: {{ sessionId | async }}</p> | ||
<a id="anchor"></a> | ||
<p>Token: {{ token | async }}</p> | ||
`, | ||
directives: [ROUTER_DIRECTIVES] | ||
directives: [] | ||
}) | ||
export class CrisisAdminComponent implements OnInit { | ||
sessionId: Observable<string>; | ||
token: Observable<string>; | ||
|
||
constructor(private router: Router) {} | ||
|
||
ngOnInit() { | ||
// Capture the session ID if available | ||
this.sessionId = this.router | ||
.routerState | ||
.queryParams | ||
.map(params => params['session_id'] || 'None'); | ||
|
||
export class CrisisAdminComponent { } | ||
// Capture the fragment if available | ||
this.token = this.router | ||
.routerState | ||
.fragment | ||
.map(fragment => fragment || 'None'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
public/docs/_examples/router/ts/app/crisis-center/crisis-list.component.1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
public/docs/_examples/router/ts/app/crisis-center/crisis-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.