Repository navigation
Nested Routing and ClearHistory: Error when route between nested routes #1052
Description
Activity
Also have this issue with the latest.
EDIT:
Running the navigate through a zone resolves the issue for us.
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?
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-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.
Almost the same scenario, except running inside zone does not work for me. Had to remove
clearHistorytemporarily until this gets resolved.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 PriceSimiliar 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 usingthis.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
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.
Removing the
destroyComponentRefcall works for us as well. That seems like something that would create a memory leak though right?18 remaining items
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.Reacted by Nicholas LaBrecque and Léo DupontReacted by Nicholas LaBrecque and Alexander VakrilovSetup is a little different, but here's a playground that shows the error:
https://play.nativescript.org/?template=play-ng&id=df0v5O&v=5My application's navigation wasn't working as well. I spent 5 hours to just discover this bug. This should be fixed.
Reacted by Léo DupontStill 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.
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
Still having this problem too 😔
any news about a fix?I have it on latest 6.2.2
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.zipReacted by Andrew ShortallI'm also having this issue.
We are also facing it. Quick fix would be appreciated. Thanks.
I'm also having this issue.
I am also having this problem when i use clearHistory
I have two routes which have child routes:
Route A
Route B
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:
Please see this animation:

The repo is using:
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.