Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

Using query parameter causes page to be outside of navigation stack [Bug]

Open GO74 opened this issue 4 years ago • 7 comments

Description

I'm creating my flyout items in code behind of AppShell.xaml.cs. I registered a route. When I call my page using a route with query parameter a back button is displayed. When I do the same without the query parameter the hamburger icon is displayed.

Steps to Reproduce

  1. Create a soulution using the template offered

  2. Delete xaml Flyout declared in AppShell.xaml

  3. Register route to a page Routing.RegisterRoute(nameof(Container), typeof(Container));

  4. Add a new item like this: Items.Add(new FlyoutItem{ FlyoutDisplayOptions = FlyoutDisplayOptions.AsSingleItem, Title = "StaticFlyoutTitle", Route = "AccessContainer", Items = { new Tab { Title = "Access", Route = "AASSWE2", Items = { new ShellContent { Title = "ShellContentTitle", Route = $"Container?bookingcodeproperty=AASSWE2", ContentTemplate = new DataTemplate(typeof(Container)), } } } } });

  5. Add another item like this: Items.Add(new FlyoutItem { FlyoutDisplayOptions = FlyoutDisplayOptions.AsSingleItem, Title = "StaticFlyoutTitle", Route = "AccessContainer", Items = { new Tab { Title = "Access", Route = "AASSWE2", Items = { new ShellContent { Title = "ShellContentTitle", Route = "Container", ContentTemplate = new DataTemplate(typeof(Container)), } } } } });

  6. Observe the different behaviour

Expected Behavior

Both FlyoutItems should behave the same

Actual Behavior

The FlyoutItem calling the page using a query paramter seems to be outside of the navigation stack. A Backbutton is displayed instead of the Hamburger.

Basic Information

  • Version with issue: vs 16.7.2, Xamarin 16.7.000.440

Workaround

Set NavBarIsVisilble to false and add a Hamburger-button with command: Shell.Current.FlyoutIsPresented = true; Dirty hack!

GO74 avatar Sep 16 '20 06:09 GO74

@GO74 what should happen here is that the app crashes with a "duplicate route" detected exception

You've registered a route

Routing.RegisterRoute(nameof(Container), typeof(Container));

And a route on the ShellContent

Route = "Container",

These are two different routes

When you click on the second FlyoutItem Shell just sends the route "Container" into shell which then uses the page you've registered here

Routing.RegisterRoute(nameof(Container), typeof(Container));

What are you trying to achieve here?

PureWeen avatar Sep 17 '20 02:09 PureWeen

@PureWeen what I'm trying to archive is to call my view using a parameter like that:

Route = $"Container?bookingcodeproperty=AASSWE2"

It should behave exactly like calling the view without the paramter, but it doesn't.

If I do it without registering a route I get this exception:

grafik

If I do register a route, I don't get an exception, but a Back-button is shown in the container-view instead of the Hamburger-button. Pressing the Back-button is opening the very same view. This doesn't make sense imho and is the reason why I think it's a bug. If I misunderstood something and made a mistake I apologise and would kindly ask for advise on how to make a call like that properly without the currently observed behavior, instead the view should have the Hamburger-button and there shouldn't be a copy of the view in the stack, just as if I would call the view without parameter.

You can observe the behaviour yourself with this: mroomote_navTest.zip

GO74 avatar Sep 17 '20 06:09 GO74

@GO74 can you tell me what your expectation is here?

What do you want the UI to look? What tabs do you want on the screen?

What do you mean by this statement?

When I call my page using a route with query parameter a back button is displayed.

PureWeen avatar Sep 17 '20 15:09 PureWeen

Sure, I expect the very same look and behaviour as if I call the view without parameter. I also explained the issue here: https://forums.xamarin.com/discussion/comment/421688#Comment_421688

GO74 avatar Sep 17 '20 16:09 GO74

@GO74 the problem is that I don't understand what your end design goal here is

If you

  • remove the register route
  • just register a ShellContent with Route "Content"
  • then navigate to that route with "\Content?Query=1"

then that won't push anything onto the navigation stack that will just pass the Query value into your BindingContext

https://devblogs.microsoft.com/xamarin/xamarin-forms-shell-query-parameters/

You don't add the parameters to the route

PureWeen avatar Sep 18 '20 16:09 PureWeen

@PureWeen Okay, got it. So this is the navigation experience I need to provide:

desired

And this is how it is currently behaving:

observed

The workaround/dirty hack I came up with is to set NavBarIsVisible = false and create my own 'NavBar' with a button which triggers the flyoutmenu.

GO74 avatar Sep 21 '20 10:09 GO74

@PureWeen I am trying to achieve something similar to what @GO74 is trying to achieve. When setting up the route if I add query parameters then the app crashes: image

The exception that is thrown is: System.ArgumentException: unable to figure out route for: //animals/domestic/cats?param1=50

The reason why I am trying to do this is to have the query parameter to have one value when navigating from the tabbar and when navigating from some other page to have a different value.

tsequeira-vhs avatar Apr 09 '21 03:04 tsequeira-vhs

Hi, I have the same problem. Has anyone solved?

Attached example

ShellRouteIssue.zip

workgroupengineering avatar Dec 23 '22 16:12 workgroupengineering