Description
Environment
Provide version numbers for the following components (information can be retrieved by running tns info
in your project folder or by inspecting the package.json
of the project):
- CLI: 5.3.4
- Cross-platform modules: 5.3.1
- Android Runtime: 5.3.1
- iOS Runtime: 5.3.1
- NativeScript-Angular: 7.2.0
- Angular: 7.2.1
Describe the bug
When navigating out of a child route component for the first time (using clearHistory: true
), the ngOnDestroy
is not getting called. Any subsequent navigations call ngOnDestroy
as expected. Reproducable on both platforms, emulators and devices.
To Reproduce
I have attached a sample project based on the hello-world Angular template. Key changes:
- Modified
app-routing.module.ts
to add child routes to the 'items' route. - Modified
items.component.html
to add arouter-outlet
for navigating between the two child routes. - Added two child components
Test1Component
andTest2Component
.
Output from the app when navigating between the two components:
CONSOLE LOG file:///app/app/item/items.component.js:16:20: ITEMS INIT
CONSOLE LOG file:///app/app/test/test1.component.js:10:20: INIT TEST1
CONSOLE LOG file:///app/app/test/test2.component.js:10:20: INIT TEST2
CONSOLE LOG file:///app/app/test/test2.component.js:13:20: DESTROY TEST2
CONSOLE LOG file:///app/app/test/test1.component.js:10:20: INIT TEST1
CONSOLE LOG file:///app/app/test/test1.component.js:13:20: DESTROY TEST1
CONSOLE LOG file:///app/app/test/test2.component.js:10:20: INIT TEST2
Expected behavior
ngOnDestroy
should be called every time when navigating out of a component using clearHistory: true
.
Sample project
ns-test-ngdestroy.zip