-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow back navigation without loosing state
- Loading branch information
1 parent
f402e9a
commit d97d484
Showing
7 changed files
with
262 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ActivatedRoute, RouterOutlet } from '@angular/router'; | ||
import { ComponentRef, Directive } from '@angular/core'; | ||
|
||
export interface OnAttach { | ||
/** | ||
* A callback method that is invoked when the RouteReuseStrategy instructs | ||
* to re-attach a previously detached component / subtree | ||
*/ | ||
onAttach(activatedRoute: ActivatedRoute): void; | ||
} | ||
|
||
export interface OnDetach { | ||
/** | ||
* A callback method that is invoked when the RouteReuseStrategy instructs | ||
* to detach component / subtree | ||
*/ | ||
onDetach(): void; | ||
} | ||
|
||
@Directive({ | ||
selector: 'app-router-outlet', | ||
}) | ||
export class AppRouterOutletDirective extends RouterOutlet { | ||
|
||
override detach(): ComponentRef<any> { | ||
const instance: any = this.component; | ||
if (instance && typeof instance.onDetach === 'function') { | ||
instance.onDetach(); | ||
} | ||
return super.detach(); | ||
} | ||
|
||
override attach(ref: ComponentRef<any>, activatedRoute: ActivatedRoute): void { | ||
super.attach(ref, activatedRoute); | ||
if (ref.instance && typeof ref.instance.onAttach === 'function') { | ||
ref.instance.onAttach(activatedRoute); | ||
} | ||
} | ||
} |
Oops, something went wrong.