Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activatedRoute parent params should check for children before emitting #11715

Closed
ocombe opened this issue Sep 19, 2016 · 1 comment
Closed

activatedRoute parent params should check for children before emitting #11715

ocombe opened this issue Sep 19, 2016 · 1 comment

Comments

@ocombe
Copy link
Contributor

ocombe commented Sep 19, 2016

I'm submitting a ...

[x] bug report => search github for a similar issue or PR before submitting

Current behavior
I have a route with a :id param and this route has 2 children like this:

{
    path: 'app/:id',
    component: AppRoute,
    children: [
      { path: 'faq', component: FaqRoute },
      { path: 'summary', component: SummaryRoute }
    ]
  }

In faq & summary I subscribe to the :id param from the parent route.

this.route.parent.params.subscribe(params => {
      console.log('getting parent params', params['id']);
      this.id = params['id'];
})

When navigating from ``/app/1/faqto/app/2/summary`, the observable emits before the ngDestroy of the current child component is triggered.

  1. FAQ: subscribe at init, with id 1
  2. change route with different id and different child path (summary in this case)
  3. the subscribe callback from the FAQ component is triggered with the new id (2)
  4. FAQ ng destroy is called
  5. summary: subscribe at init, with id 2

This bug is similar to #9827 except that in my case I'm subscribing to parent params.

Expected behavior
The router should destroy children routes before emitting the param change for the parent

Reproduction of the problem
http://plnkr.co/edit/hP3Mrjunjw4mFz4eYrtz?p=preview
check the console to see that it's getting the id before ngdestroy when navigating from summary to faq (and from faq to summary)

What is the motivation / use case for changing the behavior?
It leads to unpredictable behaviors and in my case to unnecessary server calls

  • Angular version: 2.0.0
  • Browser: all
  • Language: only tested on TypeScript 2.0.2

cc @brandonroberts (who confirmed the bug with me)

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants