Skip to content

Nested Routing and ClearHistory: Error when route between nested routes #1052

Description

@codeback

I have two routes which have child routes:

  • Route A

    • Nested Route A1
    • Nested Route A2
  • Route B

    • Nested Route B1
    • Nested Route B2

If I navigate from 'Nested Route A2' to 'Nested Route B1' with clearHistory=true, then I can not navigate anymore between 'Nested Route B1' and 'Nested Route B2'.

This repo reproduces the issue. Steps to reproduce it:

  1. Navigate to 'Angular routing' -> 'Nested routers'
  2. Click on 'SECOND' button,
  3. Click in the big button 'This is second. Load first',
  4. Now, you are in the 'Angular Routing 2' component, but you can't navigate between the nested routes.

Please see this animation:
nested_routing_clearhistory

The repo is using:

  • "nativescript-angular": "next",
  • "tns-core-modules": "next",

The problem occurs in both platforms (iOS an Android).

P.D. I know that there are several issues regarding clearHistory but I think this case is not reported. Sorry if I am wrong.

Activity

  1. sean-perkins commented on Oct 23, 2017

    @sean-perkins

    Also have this issue with the latest.

    EDIT:

    Running the navigate through a zone resolves the issue for us.

  2. codeback commented on Oct 24, 2017

    @codeback
    Author

    Hi @sean-perkins,

    Do you mean something like the following?

    this._zone.run(() => this._routerext.navigate(['/home/view-1'], {clearHistory: true}));
    

    It doesn't work in my case :(

    @vakrilov, @tsonevn have you been able to reproduce this issue? Is it related with the new route-reuse strategy?

  3. self-assigned this
    on Oct 25, 2017
  4. vakrilov commented on Oct 25, 2017

    @vakrilov
    Contributor

    Hi @codeback - I managed to reproduce the issue with your project.
    What's interesting is that there are no exceptions thrown and navigation to another page still works. Navigation onside the nested router is not working.

    @sean-perkins - Can you please share more detail on you solution using the zone. It might lead to some insights on the problem and eventually help solve it :)

  5. sean-perkins commented on Oct 25, 2017

    @sean-perkins

    In our scenario, the problem only presented itself after upgrading the Angular and NS Angular dependencies to the latest. We were on ~3.1.3 (NS Angular) beforehand. We have a lazy-loaded module that navigates the user to another lazy-loaded module, inside an event listener on a WebView.

    With no changes (only dependency upgrades and updating to NativeScriptCommonModule), the app would redirect to the lazy-loaded module and no change detection or life cycle events would occur. But, after swiping out a side drawer and tapping an action, the page would then load all the life cycle hooks.

    If we logged out of our application (which sends us back to the original lazy-loaded module) and log back in, change detection occurs, but then all navigation events are broken. Active router links are set, but the page-router-outlet doesn't actually update the component rendered.

    To solve this, we wrapped our initial navigate inside a zone.run, which fixed the problem globally. We haven't dug into it any further, as there are no logs and that makes it unproductive to debug.

  6. nikoTM commented on Oct 26, 2017

    @nikoTM

    Almost the same scenario, except running inside zone does not work for me. Had to remove clearHistory temporarily until this gets resolved.

  7. codeback commented on Oct 27, 2017

    @codeback
    Author

    In my case, remove clearHistory produces other undesirable side effects. And running inside zone does not work either. :(

    In my app the problem is that the ending route is a nested route. In other words, clearHistory=true doesn't work if the destination route is a nested route.

    My very ugly workaround is to put another route in the middle: From Route A, navigate to Route C with clearHistory=true and then, from Route C, navigate to the destination nested Route with clearHistory=true.

    Hope it helps while the issue gets resolved.

  8. added this to the milestone on Oct 31, 2017
  9. HassanMoinn commented on Feb 25, 2018

    @HassanMoinn

    Similiar issue I am having, for the past week trying to fix it but Alas !
    I am using clearHistory = true when the person starts the app again after previously logged in, so to by-pass the login screen.
    When clearHistory = true, i go to a parent route, which has children routes, these children routes are then used to navigate to different views in the same parent route using

    this.router.navigate(['appointments'], {relativeTo : this.route});

    but when clearHistory = true, nothing happens just like OP mentioned above.

    At first I thought that the routes break, but the console does not throw any error for routes break.

    P.S: without clearHistory apps behaves the way it should

  10. simonpietsch commented on Mar 9, 2018

    @simonpietsch

    Not sure if this helps to isolate the exact issue, but I've narrowed the cause of this problem to when the NSRouteReuseStrategy clears out its state cache - specifically when the cached items are destroyed.

    If the destroyComponentRef call within DetachedStateCache.clear is skipped, then child routing continues to work.

  11. llwt commented on Mar 14, 2018

    @llwt

    Removing the destroyComponentRef call works for us as well. That seems like something that would create a memory leak though right?

  12. 18 remaining items

  13. larssn commented on Dec 13, 2018

    @larssn

    Can confirm this is still a problem with nativescript-angular 7.1 and tns-core-modules 5.1. Also wanna point out that this is in the backlog for 6.2, and that ship seems to have sailed.

  14. modified the milestones: 6.2 (TBD), vNext on Jan 9, 2019
  15. pnahtanoj commented on Jan 15, 2019

    @pnahtanoj

    Setup is a little different, but here's a playground that shows the error:
    https://play.nativescript.org/?template=play-ng&id=df0v5O&v=5

  16. erkanarslan commented on Feb 8, 2019

    @erkanarslan

    My application's navigation wasn't working as well. I spent 5 hours to just discover this bug. This should be fixed.

  17. ivadym commented on Feb 28, 2019

    @ivadym

    Still an issue (Angular 7.2.6 & NativeScript 5.2.1).

    If it's helpful, a possible workaround to this problem is to create a new Custom Route Reuse Strategy.

  18. AndrePu commented on Oct 17, 2019

    @AndrePu

    Honestly, never could thought about this. It's the situation where google can't help. Only found info about this issue after discovering it by myself

  19. yahyaKacem commented on Dec 2, 2019

    @yahyaKacem

    Still having this problem too 😔
    any news about a fix?

  20. yahyaKacem commented on Dec 2, 2019

    @yahyaKacem

    I have it on latest 6.2.2

  21. msteini82 commented on Jan 5, 2020

    @msteini82

    I have the same bug on 6.3.0 ... I spent half a day just for identify it's a bug and when it happens ... now to see that it's a 2 year old bug is really annoying. Any news on it?

  22. kanclalg commented on Jan 22, 2020

    @kanclalg

    I've also spent a lot of time debugging this until I found what's happening. It is unbeliavable that it hasn't been fixed yet after more than 2 years. Here's a repo where an issue is reproduced.
    HelloWorld.zip

  23. andrewshortall commented on Feb 17, 2020

    @andrewshortall

    I'm also having this issue.

  24. vasudevpareek07 commented on Jul 9, 2020

    @vasudevpareek07

    We are also facing it. Quick fix would be appreciated. Thanks.

  25. sfrcnayds commented on Jan 26, 2021

    @sfrcnayds

    I'm also having this issue.

  26. PetroSuch commented on Dec 1, 2021

    @PetroSuch

    I am also having this problem when i use clearHistory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions