Hi EmilAlipiev-5934,
Welcome to our Microsoft Q&A platform!
Xamarin uses a navigation stack to hold the navigation pages. According to the documentation: INavigation.PopAsync Method, we can know that this method will pop the top page from the navigation stack. In other words, it can only pop one page at a time. Correspondingly, there is also an INavigation.PushAsync method to add a page to the stack, i.e., open a new page on the screen. Also, there is an INavigation.PopToRootAsync method which will pop all the extra pages and show the root page.
Now, assume that you have three pages: RootPage, MiddlePage and LastPage.
// RootPage.xaml.cs
// open MiddlePage
Shell.Current.Navigation.PushAsync(new MiddlePage());
// MiddlePage.xaml.cs
// open LastPage
Shell.Current.Navigation.PushAsync(new LastPage());
// LastPage.xaml.cs
// go back to MiddlePage
Shell.Current.Navigation.PopAsync();
// or go back to RootPage
Shell.Current.Navigation.PopToRootAsync();
As to Shell.Current.GoToAsync, it is used to navigate to a specified page based on URI. Before using it, you need to register the route.
Routing.RegisterRoute(nameof(RootPage), typeof(RootPage));
Routing.RegisterRoute(nameof(MiddlePage), typeof(MiddlePage));
Routing.RegisterRoute(nameof(LastPage), typeof(LastPage));
// RootPage.xaml.cs
// open MiddlePage
await Shell.Current.GoToAsync($"{nameof(MiddlePage)}");
// MiddlePage.xaml.cs
// open LastPage
await Shell.Current.GoToAsync($"{nameof(LastPage)}");
// LastPage.xaml.cs
// go back to MiddlePage
await Shell.Current.GoToAsync($"{nameof(MiddlePage)}");
// or
await Shell.Current.GoToAsync("..");
// or go back to RootPage
await Shell.Current.GoToAsync($"{nameof(RootPage)}");
And you can navigate to a page using "absolute routes", such as,
await Shell.Current.GoToAsync($"{nameof(MiddlePage)}/{nameof(LastPage)}");
It will show the "LastPage", and if you click the back button in the upper left corner, it will open "MiddlePage".
For more info, you can refer to Xamarin.Forms Shell navigation.
Best regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.