You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nested Routing and ClearHistory: Error when route between nested routes #1052
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:
Navigate to 'Angular routing' -> 'Nested routers'
Click on 'SECOND' button,
Click in the big button 'This is second. Load first',
Now, you are in the 'Angular Routing 2' component, but you can't navigate between the nested routes.
Please see this animation:
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.
Reacted by Sean Perkins, Garnik, Jeremiah Ogbomo, J.D Nicholls, Grey, HassanMoinn, Thang Mai, Steven Nance, Juras Norkus, Lars and 5 more
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 :)
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.
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.
Reacted by Grey, HassanMoinn, Thang Mai, Tihomir Mihaylov and Jonathan Price
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
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.
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.
Reacted by Nicholas LaBrecque and Léo Dupont
Reacted by Nicholas LaBrecque and Alexander Vakrilov
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?
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
Activity
sean-perkins commentedon Oct 23, 2017
Also have this issue with the latest.
EDIT:
Running the navigate through a zone resolves the issue for us.
codeback commentedon Oct 24, 2017
Hi @sean-perkins,
Do you mean something like the following?
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?
vakrilov commentedon Oct 25, 2017
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 :)
sean-perkins commentedon Oct 25, 2017
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-outletdoesn'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.
nikoTM commentedon Oct 26, 2017
Almost the same scenario, except running inside zone does not work for me. Had to remove
clearHistorytemporarily until this gets resolved.codeback commentedon Oct 27, 2017
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.
HassanMoinn commentedon Feb 25, 2018
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
simonpietsch commentedon Mar 9, 2018
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.
llwt commentedon Mar 14, 2018
Removing the
destroyComponentRefcall works for us as well. That seems like something that would create a memory leak though right?18 remaining items
larssn commentedon Dec 13, 2018
Can confirm this is still a problem with
nativescript-angular 7.1andtns-core-modules 5.1. Also wanna point out that this is in the backlog for 6.2, and that ship seems to have sailed.pnahtanoj commentedon Jan 15, 2019
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
erkanarslan commentedon Feb 8, 2019
My application's navigation wasn't working as well. I spent 5 hours to just discover this bug. This should be fixed.
ivadym commentedon Feb 28, 2019
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.
AndrePu commentedon Oct 17, 2019
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
yahyaKacem commentedon Dec 2, 2019
Still having this problem too 😔
any news about a fix?
yahyaKacem commentedon Dec 2, 2019
I have it on latest 6.2.2
msteini82 commentedon Jan 5, 2020
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?
kanclalg commentedon Jan 22, 2020
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
andrewshortall commentedon Feb 17, 2020
I'm also having this issue.
vasudevpareek07 commentedon Jul 9, 2020
We are also facing it. Quick fix would be appreciated. Thanks.
sfrcnayds commentedon Jan 26, 2021
I'm also having this issue.
PetroSuch commentedon Dec 1, 2021
I am also having this problem when i use clearHistory