Open sbknick opened 5 years ago
HI @sbknick,
Thank you for the provided sample project. I was able to recreate the issue on my side and I will log it as a bug, which we will investigate further. As a temporary solution. You can replace the router-outlet
with page-router-outlet
.
Ahh, my apologies, I meant to commit <page-router-outlet>
not <router-outlet>
, the bug occurs using either. The same when using .back() and .backToPreviousPage() for either.
I have a similar issue and the router.navigate
Promise resolves on the second try with the value null
. Maybe that's a bit of extra information.
I'm having exactly the same issue, are there possible workarounds?
I'm also struggling with this issue. any solution for this issue?
I am also running into this issue. Guess there's been no progress?
I found a kind of workaround, by forcing the back event on homeoutlet, when the back button leads to one of children page of HomeComponent.
Considering than /home/(homeoutlet:lounge) is the starting page, I simply added in ngOnInit method in HomeComponent :
application.android.off(application.AndroidApplication.activityBackPressedEvent);
application.android.on(application.AndroidApplication.activityBackPressedEvent, (args : application.AndroidActivityBackPressedEventData) => {
if(this.routerExtensions.router.url.indexOf("/home/(homeoutlet:") != -1 && this.routerExtensions.router.url.indexOf("/home/(homeoutlet:lounge") == -1) {
args.cancel = true;
this.routerExtensions.back({ relativeTo: this.activeRoute, outlets: ['homeoutlet'] });
}
})
That was enough for me to have the behaviour expected
Impact on this workaround: if you use a modal page in one of a children page of HomeComponent, then the back button will not close the modal
@sbknick
The behavior you observe is expected. Calling routerExtensions.back();
or routerExtensions.backToPreviousPage();
navigates back on the last navigated outlet.
When you navigate from lounge
to garage
, you navigate inside the homeoutlet
, back at this point means going back in the homeoutlet
, so you can successfully go back to lounge
.
When you navigate to work
, this is effectively navigation from home
to work
which happens inside the primary
outlet, back at this point means going back in the primary
outlet to home
(which remembered its state so the homeoutlet
is still on garage
). Going back again is an attempt to navigate back in the primary
outlet which is not possible as there is no route before home
.
In order to perform the navigation inside the homeoutlet
, you can call routerExtensions.back({ relativeTo: this.route; });
, where route
is the ActivatedRoute
service injected through the component’s constructor:
export class GarageComponent {
constructor(
private route: ActivatedRoute,
private routerExtensions: RouterExtensions
) {
console.log("garage loaded");
}
goBack() {
// Don't navigate to previous page:
// this.routerExtensions.backToPreviousPage();
// Navigate relative to the activated route instead:
this.routerExtensions.back({ relativeTo: this.route });
}
goToWork() {
this.routerExtensions.navigate(["work"]);
}
}
Nested navigation is thoroughly explained in this excellent article by Alexander Djenkov.
Hi Team ,
Any fix available for this issue?
So basically it is not possible to have a tab navigation with pages which are not part of the tab system without hacks. I think this should be better communicated in the documentation.
Is there any plan for a better support for back navigation between different outlets?
Environment Provide version numbers for the following components (information can be retrieved by running
tns info
in your project folder or by inspecting thepackage.json
of the project):Describe the bug On Android, navigation history is broken when navigating backward via nested page-router-outlets. Note: This works as expected on iOS just fine.
To Reproduce
Expected behavior If I navigate from home/lounge -> home/garage -> work, then i press back() twice, I should return to home/lounge.
Sample project https://github.com/sbknick/ns-android-nested-back-nav
Additional context On iOS, this functions as expected.