Skip to content

Child route component ngOnDestroy not called first time #1800

Open
@jnorkus

Description

@jnorkus

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:

  1. Modified app-routing.module.ts to add child routes to the 'items' route.
  2. Modified items.component.html to add a router-outlet for navigating between the two child routes.
  3. Added two child components Test1Component and Test2Component.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions