1

Our project uses the following routing structure:

        {    path: 'course/:id',
            component: PlayerComponent,
        },
        {
            path: 'course/:id/play/:id_chapter',
            component: PlayerComponent,
        },

Basically we want the same component to handle both the situation when you land on the course and when you are playing an individual chapter inside.

The issue we are facing is that, navigating between the first and second routes, the component gets destroyed (constructor, ngOnInit, ngOnDestroy called and all properties of the component lost).

We tried using a child route approach in way that we made the individual chapter route to be a child route of the main course route and this worked to some degree - we are able to navigate from the main course route to the chapter route, but if you land directly on a chapter route, Angular throws an error along the lines that no component is defined for this route (I guess Angular does not traverse the routing tree from the inner most children up until it finds a component to render).

If we follow up on the last approach and define the same component for both the parent and child routes, it fails with a different error.

Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
  • Check: https://stackoverflow.com/questions/39762485/want-to-prevent-component-recreation-while-routing-in-angular-2 – eko Dec 28 '16 at 21:11

0 Answers0