Why Back Button is hidden in Maui?

Viewed 363

I have a .Net MAUI application with Page A and Page B.

I want to move from Page A >>> Page B.

When I move using the following code, I have a back button (which is the desired behavior in my case) :

await Navigation.PushAsync(new MyPage());

However if I move to the other page using the following code, I don't have a back button :

await Shell.Current.GoToAsync("//MyPage");

For some other reasons I need to use navigation through Shell.

Does anyone know why I don't have a back button when navigating using Shell please ?

Thanks.

1 Answers

Here is the answer :

Instead of

await Shell.Current.GoToAsync("//MyPage");

I should do

await Shell.Current.GoToAsync("/MyPage");

Reason :

According to the official documentation here :

route : The route hierarchy will be searched for the specified route, upwards from the current position. The matching page will be pushed to the navigation stack.
/route : The route hierarchy will be searched from the specified route, downwards from the current position. The matching page will be pushed to the navigation stack.
//route : The route hierarchy will be searched for the specified route, upwards from the current position. The matching page will replace the navigation stack.
///route : The route hierarchy will be searched for the specified route, downwards from the current position. The matching page will replace the navigation stack.
Related