angular-docs-cn/public/docs/js/latest/api/router/CanReuse-interface.jade

48 lines
1.1 KiB
Plaintext

p.location-badge.
exported from <a href='../router'>angular2/router</a>
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.34/modules/angular2/src/router/interfaces.ts#L87-L115">angular2/src/router/interfaces.ts (line 87)</a>
:markdown
Defines route lifecycle method [canReuse], which is called by the router to determine whether a
component should be reused across routes, or whether to destroy and instantiate a new component.
If `canReuse` returns or resolves to `true`, the component instance will be reused.
If `canReuse` throws or rejects, the navigation will be cancelled.
## Example
```
@Directive({
selector: 'my-cmp'
})
class MyCmp implements CanReuse, OnReuse {
canReuse(next, prev) {
return next.params.id == prev.params.id;
}
onReuse(next, prev) {
this.id = next.params.id;
}
}
```
.l-main-section
h2 Members
.l-sub-section
h3 canReuse
pre.prettyprint
code.
canReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction)
:markdown