docs(router): Added additional router documentation including cheatsheet updates (#10802)
This commit is contained in:
parent
917d43e108
commit
cc0e3d2296
|
@ -10,7 +10,7 @@ Routing and navigation
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
syntax(ts):
|
syntax(ts):
|
||||||
`const routes: Routes = [
|
`const routes: Routes = [
|
||||||
{ path: '', HomeComponent },
|
{ path: '', component: HomeComponent },
|
||||||
{ path: 'path/:routeParam', component: MyComponent },
|
{ path: 'path/:routeParam', component: MyComponent },
|
||||||
{ path: 'staticPath', component: ... },
|
{ path: 'staticPath', component: ... },
|
||||||
{ path: '**', component: ... },
|
{ path: '**', component: ... },
|
||||||
|
@ -21,7 +21,7 @@ syntax(ts):
|
||||||
const routing = RouterModule.forRoot(routes);`|`Routes`
|
const routing = RouterModule.forRoot(routes);`|`Routes`
|
||||||
syntax(js):
|
syntax(js):
|
||||||
`var routes = [
|
`var routes = [
|
||||||
{ path: '', HomeComponent },
|
{ path: '', component: HomeComponent },
|
||||||
{ path: ':routeParam', component: MyComponent },
|
{ path: ':routeParam', component: MyComponent },
|
||||||
{ path: 'staticPath', component: ... },
|
{ path: 'staticPath', component: ... },
|
||||||
{ path: '**', component: ... },
|
{ path: '**', component: ... },
|
||||||
|
@ -32,15 +32,23 @@ syntax(js):
|
||||||
var routing = ng.router.RouterModule.forRoot(routes);`|`ng.router.Routes`
|
var routing = ng.router.RouterModule.forRoot(routes);`|`ng.router.Routes`
|
||||||
syntax(dart):
|
syntax(dart):
|
||||||
`@RouteConfig(const [
|
`@RouteConfig(const [
|
||||||
const Route(path: 'path', component: MyComponent, name: 'MyCmp' ),
|
const Route(path: '', component: HomeComponent, name: 'Home'),
|
||||||
])`|`@RouteConfig`
|
const Route(path: ':routeParam', component: MyComponent, name: 'MyCmp'),
|
||||||
|
const Route(path: 'staticPath', component: ..., name: 'StaticCmp'),
|
||||||
|
const Route(path: '**', component: ..., name: 'WildcardCmp'),
|
||||||
|
const Route(path: '/oldPath', redirectTo: ['/StaticCmp']),
|
||||||
|
const Route(path: ..., component: ..., data: { message: 'Custom' })
|
||||||
|
])class MyComponent() {}`|`@RouteConfig`
|
||||||
description:
|
description:
|
||||||
Configures routes for the application. Supports static, parameterized, redirect and wildcard routes. Also supports custom route data and resolve.
|
Configures routes for the application. Supports static, parameterized, redirect and wildcard routes. Also supports custom route data{@target ts js} and resolve{@endtarget}.
|
||||||
|
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
syntax:
|
syntax:
|
||||||
`<router-outlet></router-outlet>`|`router-outlet`
|
`
|
||||||
|
<router-outlet></router-outlet>
|
||||||
|
<router-outlet name="aux"></router-outlet>
|
||||||
|
`|`router-outlet`
|
||||||
description:
|
description:
|
||||||
Marks the location to load the component of the active route.
|
Marks the location to load the component of the active route.
|
||||||
|
|
||||||
|
@ -55,7 +63,10 @@ syntax(ts js):
|
||||||
<a [routerLink]="[ '/path' ]" fragment="anchor">
|
<a [routerLink]="[ '/path' ]" fragment="anchor">
|
||||||
`|`[routerLink]`
|
`|`[routerLink]`
|
||||||
syntax(dart):
|
syntax(dart):
|
||||||
`<a [routerLink]="[ '/MyCmp', { routeParam: 'value' } ]">Link</a>`|`[routerLink]`
|
`
|
||||||
|
<a [routerLink]="[ '/MyCmp', { routeParam: 'value' } ]">
|
||||||
|
<a [routerLink]="[ '/MyCmp', { matrixParam: 'value' } ]">
|
||||||
|
`|`[routerLink]`
|
||||||
description:
|
description:
|
||||||
Creates a link to a different view based on a route instruction consisting of a route path, required and optional parameters, query parameters and a fragment. Add the '/' prefix to navigate to a root route; add the './' prefix for a child route; add the '../sibling' prefix for a sibling or parent route.
|
Creates a link to a different view based on a route instruction consisting of a route path, required and optional parameters, query parameters and a fragment. Add the '/' prefix to navigate to a root route; add the './' prefix for a child route; add the '../sibling' prefix for a sibling or parent route.
|
||||||
|
|
||||||
|
@ -63,7 +74,7 @@ Creates a link to a different view based on a route instruction consisting of a
|
||||||
syntax(ts js):
|
syntax(ts js):
|
||||||
`<a [routerLink]="[ '/path' ]" routerLinkActive="active">`
|
`<a [routerLink]="[ '/path' ]" routerLinkActive="active">`
|
||||||
syntax(dart):
|
syntax(dart):
|
||||||
`<a [routerLink]="[ '/MyCmp', { myParam: 'value' } ]">`|`[routerLink]`
|
`<a [routerLink]="[ '/MyCmp', { myParam: 'value' } ]">`|`routerLink`
|
||||||
description:
|
description:
|
||||||
The provided class(es) will be added to the element when the routerLink becomes the current active route.
|
The provided class(es) will be added to the element when the routerLink becomes the current active route.
|
||||||
|
|
||||||
|
@ -73,14 +84,14 @@ syntax(ts):
|
||||||
canActivate(
|
canActivate(
|
||||||
route: ActivatedRouteSnapshot,
|
route: ActivatedRouteSnapshot,
|
||||||
state: RouterStateSnapshot
|
state: RouterStateSnapshot
|
||||||
): Observable<boolean> | boolean { ... }
|
): Observable<boolean>|Promise<boolean>|boolean { ... }
|
||||||
}
|
}
|
||||||
|
|
||||||
{ path: ..., canActivate: [CanActivateGuard] }`|`CanActivate`
|
{ path: ..., canActivate: [CanActivateGuard] }`|`CanActivate`
|
||||||
syntax(js):
|
syntax(js):
|
||||||
`var CanActivateGuard = ng.core.Class({
|
`var CanActivateGuard = ng.core.Class({
|
||||||
canActivate: function(route, state) {
|
canActivate: function(route, state) {
|
||||||
// return Observable boolean or boolean
|
// return Observable/Promise boolean or boolean
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -88,7 +99,7 @@ syntax(js):
|
||||||
syntax(dart):
|
syntax(dart):
|
||||||
`@CanActivate(() => ...)class MyComponent() {}`|`@CanActivate`
|
`@CanActivate(() => ...)class MyComponent() {}`|`@CanActivate`
|
||||||
description:
|
description:
|
||||||
{@target js ts}An interface for defining a class that the router should call first to determine if it should activate this component. Should return a boolean or a Observable that resolves a boolean{@endtarget}
|
{@target js ts}An interface for defining a class that the router should call first to determine if it should activate this component. Should return an Observable/Promise that resolves a boolean or a boolean{@endtarget}
|
||||||
{@target dart}A component decorator defining a function that the router should call first to determine if it should activate this component. Should return a boolean or a future.{@endtarget}
|
{@target dart}A component decorator defining a function that the router should call first to determine if it should activate this component. Should return a boolean or a future.{@endtarget}
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
|
@ -98,14 +109,14 @@ syntax(ts):
|
||||||
component: T,
|
component: T,
|
||||||
route: ActivatedRouteSnapshot,
|
route: ActivatedRouteSnapshot,
|
||||||
state: RouterStateSnapshot
|
state: RouterStateSnapshot
|
||||||
): Observable<boolean> | boolean { ... }
|
): Observable<boolean>|Promise<boolean>|boolean { ... }
|
||||||
}
|
}
|
||||||
|
|
||||||
{ path: ..., canDeactivate: [CanDeactivateGuard] }`|`CanDeactivate`
|
{ path: ..., canDeactivate: [CanDeactivateGuard] }`|`CanDeactivate`
|
||||||
syntax(js):
|
syntax(js):
|
||||||
`var CanDeactivateGuard = ng.core.Class({
|
`var CanDeactivateGuard = ng.core.Class({
|
||||||
canDeactivate: function(component, route, state) {
|
canDeactivate: function(component, route, state) {
|
||||||
// return Observable boolean or boolean
|
// return Observable/Promise boolean or boolean
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -113,10 +124,30 @@ syntax(js):
|
||||||
syntax(dart):
|
syntax(dart):
|
||||||
`routerCanDeactivate(nextInstruction, prevInstruction) { ... }`|`routerCanDeactivate`
|
`routerCanDeactivate(nextInstruction, prevInstruction) { ... }`|`routerCanDeactivate`
|
||||||
description:
|
description:
|
||||||
{@target js ts}An interface for defining a class that the router should call first to determine if it should deactivate this component after a navigation. Should return a boolean or a Observable that resolves a boolean{@endtarget}
|
{@target js ts}An interface for defining a class that the router should call first to determine if it should deactivate this component after a navigation. Should return an Observable/Promise that resolves a boolean or a boolean{@endtarget}
|
||||||
{@target dart}
|
{@target dart}
|
||||||
The router calls the routerCanDeactivate methods (if defined) of every component that would be removed after a navigation. The navigation proceeds if and only if all such methods return true or a future that completes successfully{@endtarget}.
|
The router calls the routerCanDeactivate methods (if defined) of every component that would be removed after a navigation. The navigation proceeds if and only if all such methods return true or a future that completes successfully{@endtarget}.
|
||||||
|
|
||||||
|
@cheatsheetItem
|
||||||
|
syntax(ts):
|
||||||
|
`class CanActivateChildGuard implements CanActivateChild {
|
||||||
|
canActivateChild(
|
||||||
|
route: ActivatedRouteSnapshot,
|
||||||
|
state: RouterStateSnapshot
|
||||||
|
): Observable<boolean>|Promise<boolean>|boolean { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ path: ..., canActivateChild: [CanActivateGuard], children: ... }`|`CanActivateChild`
|
||||||
|
syntax(js):
|
||||||
|
`var CanActivateChildGuard = ng.core.Class({
|
||||||
|
canActivateChild: function(route, state) {
|
||||||
|
// return Observable/Promise boolean or boolean
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
{ path: ..., canActivateChild: [CanActivateChildGuard], children: ... }`|`CanActivateChild`
|
||||||
|
description:
|
||||||
|
{@target js ts}An interface for defining a class that the router should call first to determine if it should activate the child route. Should return an Observable/Promise that resolves a boolean or a boolean{@endtarget}
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
syntax(ts):
|
syntax(ts):
|
||||||
|
@ -124,20 +155,40 @@ syntax(ts):
|
||||||
resolve(
|
resolve(
|
||||||
route: ActivatedRouteSnapshot,
|
route: ActivatedRouteSnapshot,
|
||||||
state: RouterStateSnapshot
|
state: RouterStateSnapshot
|
||||||
): Observable<any> | any { ... }
|
): Observable<any>|Promise<any>|any { ... }
|
||||||
}
|
}
|
||||||
|
|
||||||
{ path: ..., resolve: [ResolveGuard] }`|`Resolve`
|
{ path: ..., resolve: [ResolveGuard] }`|`Resolve`
|
||||||
syntax(js):
|
syntax(js):
|
||||||
`var ResolveGuard = ng.core.Class({
|
`var ResolveGuard = ng.core.Class({
|
||||||
resolve: function(route, state) {
|
resolve: function(route, state) {
|
||||||
// return Observable value or value
|
// return Observable/Promise value or value
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
{ path: ..., resolve: [ResolveGuard] }`|`Resolve`
|
{ path: ..., resolve: [ResolveGuard] }`|`Resolve`
|
||||||
description:
|
description:
|
||||||
{@target js ts}An interface for defining a class that the router should call first to resolve route data before rendering the route. Should return a value or an Observable that resolves a value{@endtarget}
|
{@target js ts}An interface for defining a class that the router should call first to resolve route data before rendering the route. Should return an Observable/Promise that resolves a value or a value{@endtarget}
|
||||||
|
|
||||||
|
@cheatsheetItem
|
||||||
|
syntax(ts):
|
||||||
|
`class CanLoadGuard implements CanLoad {
|
||||||
|
canLoad(
|
||||||
|
route: Route
|
||||||
|
): Observable<boolean>|Promise<boolean>|boolean { ... }
|
||||||
|
}
|
||||||
|
|
||||||
|
{ path: ..., canLoad: [CanLoadGuard], loadChildren: ... }`|`CanLoad`
|
||||||
|
syntax(js):
|
||||||
|
`var CanLoadGuard = ng.core.Class({
|
||||||
|
canLoad: function(route) {
|
||||||
|
// return Observable/Promise boolean or boolean
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
{ path: ..., canLoad: [CanLoadGuard], loadChildren: ... }`|`CanLoad`
|
||||||
|
description:
|
||||||
|
{@target js ts}An interface for defining a class that the router should call first to check if the lazy loaded module should be loaded. Should return an Observable/Promise that resolves a boolean or a boolean{@endtarget}
|
||||||
|
|
||||||
@cheatsheetItem
|
@cheatsheetItem
|
||||||
syntax(dart):
|
syntax(dart):
|
||||||
|
@ -171,4 +222,4 @@ description:
|
||||||
syntax(dart):
|
syntax(dart):
|
||||||
`routerOnDeactivate(nextInstruction, prevInstruction) { ... }`|`routerOnDeactivate`
|
`routerOnDeactivate(nextInstruction, prevInstruction) { ... }`|`routerOnDeactivate`
|
||||||
description:
|
description:
|
||||||
{@target dart}Called before the directive is removed as the result of a route change. May return a future that pauses removing the directive until the future completes.{@endtarget}
|
{@target dart}Called before the directive is removed as the result of a route change. May return a future that pauses removing the directive until the future completes.{@endtarget}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
import {Type} from '@angular/core';
|
import {Type} from '@angular/core';
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `Routes` is an array of route configurations. Each one has the following properties:
|
* `Routes` is an array of route configurations. Each one has the following properties:
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,34 +22,48 @@ import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
|
||||||
* class CanActivateTeam implements CanActivate {
|
* class CanActivateTeam implements CanActivate {
|
||||||
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
||||||
*
|
*
|
||||||
* canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> {
|
* canActivate(
|
||||||
* return this.permissions.canActivate(this.currentUser, this.route.params.id);
|
* route: ActivatedRouteSnapshot,
|
||||||
|
* state: RouterStateSnapshot
|
||||||
|
* ): Observable<boolean>|Promise<boolean>|boolean {
|
||||||
|
* return this.permissions.canActivate(this.currentUser, route.params.id);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* CanActivateTeam,
|
* imports: [
|
||||||
*
|
* RouterModule.forRoot([
|
||||||
* provideRouter([{
|
* {
|
||||||
* path: 'team/:id',
|
* path: 'team/:id',
|
||||||
* component: Team,
|
* component: TeamCmp,
|
||||||
* canActivate: [CanActivateTeam]
|
* canActivate: [CanActivateTeam]
|
||||||
* }])
|
* }
|
||||||
* ]);
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [CanActivateTeam]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* You can also provide a function with the same signature instead of the class:
|
* You can also provide a function with the same signature instead of the class:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* {provide: 'canActivateTeam', useValue: (route: ActivatedRouteSnapshot, state:
|
* imports: [
|
||||||
* RouterStateSnapshot) => true},
|
* RouterModule.forRoot([
|
||||||
* provideRouter([{
|
* {
|
||||||
* path: 'team/:id',
|
* path: 'team/:id',
|
||||||
* component: Team,
|
* component: TeamCmp,
|
||||||
* canActivate: ['canActivateTeam']
|
* canActivate: ['canActivateTeam']
|
||||||
* }])
|
* }
|
||||||
* ]);
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [
|
||||||
|
* {
|
||||||
|
* provide: 'canActivateTeam',
|
||||||
|
* useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => true
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @stable
|
* @stable
|
||||||
|
@ -69,47 +83,58 @@ export interface CanActivate {
|
||||||
* class CanActivateTeam implements CanActivate {
|
* class CanActivateTeam implements CanActivate {
|
||||||
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
||||||
*
|
*
|
||||||
* canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean>
|
* canActivateChild(
|
||||||
* {
|
* route: ActivatedRouteSnapshot,
|
||||||
|
* state: RouterStateSnapshot
|
||||||
|
* ): Observable<boolean>|Promise<boolean>|boolean {
|
||||||
* return this.permissions.canActivate(this.currentUser, route.params.id);
|
* return this.permissions.canActivate(this.currentUser, route.params.id);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* CanActivateTeam,
|
* imports: [
|
||||||
*
|
* RouterModule.forRoot([
|
||||||
* provideRouter([
|
* {
|
||||||
* {
|
* path: 'root',
|
||||||
* path: 'root',
|
* canActivateChild: [CanActivateTeam],
|
||||||
* canActivateChild: [CanActivateTeam],
|
* children: [
|
||||||
* children: [
|
* {
|
||||||
* {
|
* path: 'team/:id',
|
||||||
* path: 'team/:id',
|
* component: Team
|
||||||
* component: Team
|
* }
|
||||||
* }
|
* ]
|
||||||
* ]
|
* }
|
||||||
* }
|
* ])
|
||||||
* ]);
|
* ],
|
||||||
|
* providers: [CanActivateTeam]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* You can also provide a function with the same signature instead of the class:
|
* You can also provide a function with the same signature instead of the class:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* {provide: 'canActivateTeam', useValue: (route: ActivatedRouteSnapshot, state:
|
* imports: [
|
||||||
* RouterStateSnapshot) => true},
|
* RouterModule.forRoot([
|
||||||
* provideRouter([
|
* {
|
||||||
|
* path: 'root',
|
||||||
|
* canActivateChild: ['canActivateTeam'],
|
||||||
|
* children: [
|
||||||
|
* {
|
||||||
|
* path: 'team/:id',
|
||||||
|
* component: Team
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [
|
||||||
* {
|
* {
|
||||||
* path: 'root',
|
* provide: 'canActivateTeam',
|
||||||
* canActivateChild: ['canActivateTeam'],
|
* useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => true
|
||||||
* children: [
|
* }
|
||||||
* {
|
* ]
|
||||||
* path: 'team/:id',
|
* })
|
||||||
* component: Team
|
|
||||||
* }
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
* ]);
|
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @stable
|
* @stable
|
||||||
|
@ -127,37 +152,52 @@ export interface CanActivateChild {
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* @Injectable()
|
* @Injectable()
|
||||||
* class CanDeactivateTeam implements CanDeactivate {
|
* class CanDeactivateTeam implements CanDeactivate<TeamComponent> {
|
||||||
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
||||||
*
|
*
|
||||||
* canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> {
|
* canDeactivate(
|
||||||
|
* component: TeamComponent,
|
||||||
|
* route: ActivatedRouteSnapshot,
|
||||||
|
* state: RouterStateSnapshot
|
||||||
|
* ): Observable<boolean>|Promise<boolean>|boolean {
|
||||||
* return this.permissions.canDeactivate(this.currentUser, route.params.id);
|
* return this.permissions.canDeactivate(this.currentUser, route.params.id);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* CanDeactivateTeam,
|
* imports: [
|
||||||
*
|
* RouterModule.forRoot([
|
||||||
* provideRouter([{
|
* {
|
||||||
* path: 'team/:id',
|
* path: 'team/:id',
|
||||||
* component: Team,
|
* component: TeamCmp,
|
||||||
* canDeactivate: [CanDeactivateTeam]
|
* canDeactivate: [CanDeactivateTeam]
|
||||||
* }])
|
* }
|
||||||
* ]);
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [CanDeactivateTeam]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* You can also provide a function with the same signature instead of the class:
|
* You can also provide a function with the same signature instead of the class:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* {provide: 'canDeactivateTeam', useValue: (route: ActivatedRouteSnapshot, state:
|
* imports: [
|
||||||
* RouterStateSnapshot) => true},
|
* RouterModule.forRoot([
|
||||||
* provideRouter([{
|
* {
|
||||||
* path: 'team/:id',
|
* path: 'team/:id',
|
||||||
* component: Team,
|
* component: TeamCmp,
|
||||||
* canActivate: ['canDeactivateTeam']
|
* canActivate: ['canDeactivateTeam']
|
||||||
* }])
|
* }
|
||||||
* ]);
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [
|
||||||
|
* {
|
||||||
|
* provide: 'canDeactivateTeam',
|
||||||
|
* useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => true
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @stable
|
* @stable
|
||||||
|
@ -174,29 +214,56 @@ export interface CanDeactivate<T> {
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* @Injectable()
|
* @Injectable()
|
||||||
* class TeamResolver implements Resolve {
|
* class TeamResolver implements Resolve<Team> {
|
||||||
* constructor(private backend: Backend) {}
|
* constructor(private backend: Backend) {}
|
||||||
*
|
*
|
||||||
* resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<any> {
|
* resolve(
|
||||||
* return this.backend.fetchTeam(this.route.params.id);
|
* route: ActivatedRouteSnapshot,
|
||||||
|
* state: RouterStateSnapshot
|
||||||
|
* ): Observable<any>|Promise<any>|any {
|
||||||
|
* return this.backend.fetchTeam(route.params.id);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* TeamResolver,
|
* imports: [
|
||||||
*
|
* RouterModule.forRoot([
|
||||||
* provideRouter([{
|
* {
|
||||||
* path: 'team/:id',
|
* path: 'team/:id',
|
||||||
* component: TeamCmp,
|
* component: TeamCmp,
|
||||||
* resolve: {
|
* resolve: {
|
||||||
* team: TeamResolver
|
* team: TeamResolver
|
||||||
* }
|
* }
|
||||||
* }])
|
* }
|
||||||
* ]);
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [TeamResolver]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* You can also provide a function with the same signature instead of the class.
|
* You can also provide a function with the same signature instead of the class.
|
||||||
*
|
*
|
||||||
|
* ```
|
||||||
|
* @NgModule({
|
||||||
|
* imports: [
|
||||||
|
* RouterModule.forRoot([
|
||||||
|
* {
|
||||||
|
* path: 'team/:id',
|
||||||
|
* component: TeamCmp,
|
||||||
|
* resolve: {
|
||||||
|
* team: 'teamResolver'
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [
|
||||||
|
* {
|
||||||
|
* provide: 'teamResolver',
|
||||||
|
* useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => 'team'
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
* @stable
|
* @stable
|
||||||
*/
|
*/
|
||||||
export interface Resolve<T> {
|
export interface Resolve<T> {
|
||||||
|
@ -215,37 +282,51 @@ export interface Resolve<T> {
|
||||||
* class CanLoadTeamSection implements CanLoad {
|
* class CanLoadTeamSection implements CanLoad {
|
||||||
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
* constructor(private permissions: Permissions, private currentUser: UserToken) {}
|
||||||
*
|
*
|
||||||
* canLoad(route: Route):Observable<boolean> {
|
* canLoad(route: Route(
|
||||||
|
* route: Route
|
||||||
|
* ): Observable<boolean>|Promise<boolean>|boolean {
|
||||||
* return this.permissions.canLoadChildren(this.currentUser, route);
|
* return this.permissions.canLoadChildren(this.currentUser, route);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* CanLoadTeamSection,
|
* imports: [
|
||||||
*
|
* RouterModule.forRoot([
|
||||||
* provideRouter([{
|
* {
|
||||||
* path: 'team/:id',
|
* path: 'team/:id',
|
||||||
* component: Team,
|
* component: TeamCmp,
|
||||||
* loadChildren: 'team.js',
|
* loadChildren: 'team.js',
|
||||||
* canLoad: [CanLoadTeamSection]
|
* canLoad: [CanLoadTeamSection]
|
||||||
* }])
|
* }
|
||||||
* ]);
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [CanLoadTeamSection]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* You can also provide a function with the same signature instead of the class:
|
* You can also provide a function with the same signature instead of the class:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* bootstrap(AppComponent, [
|
* @NgModule({
|
||||||
* {provide: 'canLoadTeamSection', useValue: (route: Route) => true},
|
* imports: [
|
||||||
* provideRouter([{
|
* RouterModule.forRoot([
|
||||||
* path: 'team/:id',
|
* {
|
||||||
* component: Team,
|
* path: 'team/:id',
|
||||||
* loadChildren: 'team.js',
|
* component: TeamCmp,
|
||||||
* canLoad: ['canLoadTeamSection']
|
* loadChildren: 'team.js',
|
||||||
* }])
|
* canLoad: ['canLoadTeamSection']
|
||||||
* ]);
|
* }
|
||||||
|
* ])
|
||||||
|
* ],
|
||||||
|
* providers: [
|
||||||
|
* {
|
||||||
|
* provide: 'canLoadTeamSection',
|
||||||
|
* useValue: (route: Route) => true
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @stable
|
* @stable
|
||||||
*/
|
*/
|
||||||
export interface CanLoad { canLoad(route: Route): Observable<boolean>|Promise<boolean>|boolean; }
|
export interface CanLoad { canLoad(route: Route): Observable<boolean>|Promise<boolean>|boolean; }
|
||||||
|
|
|
@ -40,12 +40,95 @@ declare var Zone: any;
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export interface NavigationExtras {
|
export interface NavigationExtras {
|
||||||
|
/**
|
||||||
|
* Enables relative navigation from the current ActivatedRoute
|
||||||
|
*
|
||||||
|
* Configuration
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* [{
|
||||||
|
* path: 'parent',
|
||||||
|
* component: ParentComponent,
|
||||||
|
* children: [
|
||||||
|
* {
|
||||||
|
* path: 'list',
|
||||||
|
* component: ListComponent
|
||||||
|
* },
|
||||||
|
* {
|
||||||
|
* path: 'child',
|
||||||
|
* component: ChildComponent
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* }]
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Navigate to list route from child route
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* @Component({...})
|
||||||
|
* class ChildComponent {
|
||||||
|
* constructor(private router: Router, private route: ActivatedRoute) {}
|
||||||
|
*
|
||||||
|
* go() {
|
||||||
|
* this.router.navigate('../list', { relativeTo: this.route });
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
relativeTo?: ActivatedRoute;
|
relativeTo?: ActivatedRoute;
|
||||||
|
/**
|
||||||
|
* Sets query parameters to the URL
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* // Navigate to /results?page=1
|
||||||
|
* this.router.navigate('/results', { queryParams: { page: 1 } });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
queryParams?: Params;
|
queryParams?: Params;
|
||||||
|
/**
|
||||||
|
* Sets the hash fragment for the URL
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* // Navigate to /results#top
|
||||||
|
* this.router.navigate('/results', { fragment: 'top' });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
fragment?: string;
|
fragment?: string;
|
||||||
|
/**
|
||||||
|
* Preserves the query parameters for the next navigation
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* // Preserve query params from /results?page=1 to /view?page=1
|
||||||
|
* this.router.navigate('/view', { preserveQueryParams: true });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
preserveQueryParams?: boolean;
|
preserveQueryParams?: boolean;
|
||||||
|
/**
|
||||||
|
* Preserves the fragment for the next navigation
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* // Preserve fragment from /results#top to /view#top
|
||||||
|
* this.router.navigate('/view', { preserveFragment: true });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
preserveFragment?: boolean;
|
preserveFragment?: boolean;
|
||||||
|
/**
|
||||||
|
* Navigates without pushing a new state into history
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* // Navigate silently to /view
|
||||||
|
* this.router.navigate('/view', { skipLocationChange: true });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
skipLocationChange?: boolean;
|
skipLocationChange?: boolean;
|
||||||
|
/**
|
||||||
|
* Navigates while replacing the current state in history
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* // Navigate to /view
|
||||||
|
* this.router.navigate('/view', { replaceUrl: true });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
replaceUrl?: boolean;
|
replaceUrl?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ export const ROUTER_PROVIDERS: any[] = [
|
||||||
* bootstrap(AppCmp, {imports: [RouterModule.forRoot(ROUTES)]});
|
* bootstrap(AppCmp, {imports: [RouterModule.forRoot(ROUTES)]});
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* For lazy loaded modules it should be used as follows:
|
* For submodules and lazy loaded submodules it should be used as follows:
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
*
|
*
|
||||||
|
@ -167,4 +167,4 @@ export function provideRouterInitializer() {
|
||||||
useFactory: initialRouterNavigation,
|
useFactory: initialRouterNavigation,
|
||||||
deps: [Router]
|
deps: [Router]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue