Skip to content

Commit fa2c679

Browse files
committed
docs(router): improve docs for RouterOutlet methods
Closes angular#3909
1 parent ad16e9d commit fa2c679

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

modules/angular2/src/router/router_outlet.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export class RouterOutlet {
4040
}
4141
}
4242

43+
/**
44+
* Called by the Router to instantiate a new component during the commit phase of a navigation.
45+
* This method in turn is responsible for calling the `onActivate` hook of its child.
46+
*/
4347
activate(nextInstruction: ComponentInstruction): Promise<any> {
4448
var previousInstruction = this._currentInstruction;
4549
this._currentInstruction = nextInstruction;
@@ -61,6 +65,11 @@ export class RouterOutlet {
6165
});
6266
}
6367

68+
/**
69+
* Called by the {@link Router} during the commit phase of a navigation when an outlet
70+
* reuses a component between different routes.
71+
* This method in turn is responsible for calling the `onReuse` hook of its child.
72+
*/
6473
reuse(nextInstruction: ComponentInstruction): Promise<any> {
6574
var previousInstruction = this._currentInstruction;
6675
this._currentInstruction = nextInstruction;
@@ -74,6 +83,10 @@ export class RouterOutlet {
7483
true);
7584
}
7685

86+
/**
87+
* Called by the {@link Router} when an outlet reuses a component across navigations.
88+
* This method in turn is responsible for calling the `onReuse` hook of its child.
89+
*/
7790
deactivate(nextInstruction: ComponentInstruction): Promise<any> {
7891
var next = _resolveToTrue;
7992
if (isPresent(this._componentRef) && isPresent(this._currentInstruction) &&
@@ -90,7 +103,12 @@ export class RouterOutlet {
90103
}
91104

92105
/**
93-
* Called by Router during recognition phase
106+
* Called by the {@link Router} during recognition phase of a navigation.
107+
*
108+
* If this resolves to `false`, the given navigation is cancelled.
109+
*
110+
* This method delegates to the child component's `canDeactivate` hook if it exists,
111+
* and otherwise resolves to true.
94112
*/
95113
canDeactivate(nextInstruction: ComponentInstruction): Promise<boolean> {
96114
if (isBlank(this._currentInstruction)) {
@@ -103,9 +121,15 @@ export class RouterOutlet {
103121
return _resolveToTrue;
104122
}
105123

106-
107124
/**
108-
* Called by Router during recognition phase
125+
* Called by the {@link Router} during recognition phase of a navigation.
126+
*
127+
* If the new child component has a different Type than the existing child component,
128+
* this will resolve to `false`. You can't reuse an old component when the new component
129+
* is of a different Type.
130+
*
131+
* Otherwise, this method delegates to the child component's `canReuse` hook if it exists,
132+
* or resolves to true if the hook is not present.
109133
*/
110134
canReuse(nextInstruction: ComponentInstruction): Promise<boolean> {
111135
var result;

0 commit comments

Comments
 (0)