How to clear the Navigation Stack in a Xamarin.Forms 4.0+ Shell app?

I like to remove all pages from the navigation stack and make my current page the new root page. How can I do that?
Whole navigation is done with the new Shell navigation (calling Shell.GoToAsync(route) or the Flyout Menu).
I tried collecting the current stack from Shell.Current.CurrentItem.Navigation.NavigationStack and Shell.Current.Navigation.NavigationStack , but the only element in there is null for any reason.
I am using the latest Xamarin 4.2.848062 version.

Best Answer

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited October 16

    I like to remove all pages from the navigation stack and make my current page the new root page.

    Xamarin.Forms Shell includes a URI-based navigation experience that uses routes to navigate to any page in the application, without having to follow a set navigation hierarchy. In addition, it also provides the ability to navigate backwards without having to visit all of the pages on the navigation stack. So, you cannot get the page from shell's NavigationStack.

    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation

  • thisismyselfthisismyself Member ✭✭

    In addition, it also provides the ability to navigate backwards without having to visit all of the pages on the navigation stack.

    You mean I can go backward anywhere I want cause I can navigate to any URI at any time? But my Android Back Button goes there where he wants, namely down the Navigation Stack.

    So, you cannot get the page from shell's NavigationStack.

    I don't see the relation between this and the quote before. We shouldn't it be possible to remove pages from the Navigation Stack? Why should there be the property Navigation which has the property NavigationStack on the ShellItem?

  • thisismyselfthisismyself Member ✭✭

    Someone has faced the similar problem

    Thank you for that hint, thank for trying to reproduce. I faced a very simliar issue like the reporter, when I tried to switch between two AppShells. I did not expect these two issue could be related. This is the discussion I started about: https://forums.xamarin.com/discussion/comment/391896
    I will definitly keep an eye on the issue you linked.

    Thank you very much.

Sign In or Register to comment.