Xamarin Forms Shell - Navigation to old navigation stack rather than flyout page

I’m having trouble with my Xamarin Forms Shell app. I'm not sure if this is a bug or expected behaviour, can someone point me in the right direction.

I have an app with 2 pages in the Visual Shell Hierarchy:

Search & History

<FlyoutItem Title="Search" Icon="search.png">
    <Tab Title="Search">
        <ShellContent Route="searchpage">
            <views:SearchPage />
        </ShellContent>
    </Tab>
</FlyoutItem>
<FlyoutItem Title="History" Icon="history.png">
    <Tab Title="History">
        <ShellContent>
            <views:HistoryPage />
        </ShellContent>
    </Tab>
</FlyoutItem>

And several pages (let’s call them PageA, PageB and PageC) registered like so:

Routing.RegisterRoute("PageA", typeof(PageA));    
Routing.RegisterRoute("PageB", typeof(PageB));    
Routing.RegisterRoute("PageC", typeof(PageC)); (Oops, I should probably use nameof here)

Anyway, I start on the Search page and navigate to PageA like so:

Shell.Current.GoToAsync("PageA");

Because PageA is not in the visual hierarchy, this gives me a navigation stack like so:

"//searchpage/PageA"

Using the same relative navigation approach, I navigate to PageB then PageC, so my navigation stack is like so:

"//searchpage/PageA/PageB/PageC"

From PageC, I use the flyout menu to navigate to History, the history page opens fine.

Now on the history page, I use the flyout menu again and click the Search tab

But I'm not taken to the search page as expected, I'm taken back to PageC (taken back to my previous navigation stack).

From this page (PageC) if I use the flyout menu again and click the Search tab, it navigates correctly to the Search page.

How should this work and how can I stop it navigating to PageC when I select the Search tab from the flyout?

Thanks

(ps - I'm using Xamarin Forms 4.7 at present)


Solution 1:

For those still looking for answers, an answer by Damir's Corner

await Shell.Current.GoToAsync($"///{tag}", false); //Checks the Navigation Stack Downward

The code above checks the current Navigation Stack, and searches for the Route Tag Downward (or inside the Navigation Stack) and then replaces the entire Stack with the Found Route.

Hope this helps for those looking for answers.

Solution 2:

When jumping between different tabs (and by doing so different navigationstacks), Williams solution (Damir's Corner) worked for me.

My scenario:

  • Tab1 -> ListPage -> DetailsPage
  • Tab2 -> CreateStep1Page -> CreateStep2Page

After saving the entry in CreateSpecificPage, I navigate two times:

await Shell.Current.GoToAsync($"///{nameof(CreateStep1Page)}", false);
await Shell.Current.GoToAsync($"///{nameof(ListPage)}/{nameof(DetailsPage)}", true);