Net Maui Shell How to back button command for multi pages ?

Sami 856 Reputation points
2023-10-31T23:06:08.3233333+00:00

I have multi pages on shell navigation like this

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

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

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

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

Public AppShell()

{

           InitializeComponent();
           BindingContext = this;
           Routing.RegisterRoute("aaa", typeof(APage));
           Routing.RegisterRoute("bbb", typeof(BPage));
           Routing.RegisterRoute("ccc", typeof(CPage));
           Routing.RegisterRoute("ddd", typeof(DPage));

}

then on viewmodel I have created global back command like this

    public ICommand BackCommand { get; } = new Command(async () => await Shell.Current.GoToAsync(".."));

first page is going back as expected but the other pages is not working how to do that ?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,870 questions
{count} votes