Anton Motin
Anton Motin

Reputation: 51

How can I navigate to a new page, that will have Shell flyout menu?

I need to navigate to a page, that will have shell flyout menu, but I don't need it present as item in menu.

I have tried routing pages

Routing.RegisterRoute("cart", typeof(Cart));

and then use

Shell.Current.GoToAsync("///cart");

But it throws an error, telling me about the only page in stack. Microsoft documentation doesn't help.

Global routes currently cannot be the only page on the stack, so absolute routing to global routes is not supported. For now, just navigate to: cart/

When I tried

Shell.Current.Navigation.PushAsync(new NavigationPage(new Cart()));

It worked, but topbar was default color and menu button wasn't there. Also, I have tried to push Cart as a new page, without new NavigationPage(), topbar has no changes, but menubutton works as BackButton, even though I set a Behaviour

<Shell.BackButtonBehavior>
        <BackButtonBehavior IconOverride="back.png"/>
</Shell.BackButtonBehavior>

Upvotes: 1

Views: 8933

Answers (3)

Dmitri
Dmitri

Reputation: 776

This worked in my case:

// without parameter
await Shell.Current.GoToAsync("//cart");
// or with parameter
await Shell.Current.GoToAsync($"//cart?item=12345");

Upvotes: 3

Ryan Motal
Ryan Motal

Reputation: 372

Using Shell.Current.GoToAsync will just push another page in your navigation stack,

If you want to navigate to another navigation page using shell, you can just create another Shell File, ex. AppShell.xaml(default for shell) and just change your MainPage by

Application.Current.MainPage = new NewAppShell();

Upvotes: 7

Lucas Zhang
Lucas Zhang

Reputation: 18861

Cause:

Your path ///cart is invalid . Global routes currently can't be the only page on the navigation stack. Therefore, absolute routing to global routes is unsupported.

Solution:

Navigation can also be performed by specifying a valid relative URI as an argument to the GoToAsync method. The routing system will attempt to match the URI to a ShellContent object. Therefore, if all the routes in an application are unique, navigation can be performed by only specifying the unique route name as a relative URI:

await Shell.Current.GoToAsync("cart");

Upvotes: 0

Related Questions