Skip to content

Fixed Query parameters not passed on Shell navigation #30034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Controls/src/Core/Shell/ShellContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ Page IShellContentController.GetOrCreateContent()
}

result = ContentCache ?? (Page)template.CreateContent(content, this);

if (GetValue(QueryAttributesProperty) is ShellRouteParameters delayedQueryParams)
{
result?.SetValue(QueryAttributesProperty, delayedQueryParams);
}

ContentCache = result;
}

Expand All @@ -104,9 +110,6 @@ Page IShellContentController.GetOrCreateContent()
if (result is NavigationPage)
throw new NotSupportedException("Shell is currently not compatible with NavigationPage. Shell has Navigation built in and doesn't require a NavigationPage.");

if (GetValue(QueryAttributesProperty) is ShellRouteParameters delayedQueryParams)
result.SetValue(QueryAttributesProperty, delayedQueryParams);

return result;
}

Expand Down
82 changes: 82 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue10509.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 10509, "Query parameter is missing after navigation", PlatformAffected.Android)]
public class Issue10509 : Shell
{
public Issue10509()
{
Routing.RegisterRoute(nameof(Issue10509Page1), typeof(Issue10509Page1));
Routing.RegisterRoute(nameof(Issue10509Page2), typeof(Issue10509Page2));

Items.Add(new ShellContent
{
Title = "First Page",
Route = nameof(Issue10509Page1),
ContentTemplate = new DataTemplate(typeof(Issue10509Page1))
});

Items.Add(new ShellContent
{
Title = "Second Page",
Route = nameof(Issue10509Page2),
ContentTemplate = new DataTemplate(typeof(Issue10509Page2))
});
}
}

public class Issue10509Page1 : ContentPage
{
public Issue10509Page1()
{
var navigateBtn = new Button
{
Text = "Navigate to Page 2",
HorizontalOptions = LayoutOptions.Center,
AutomationId = "Page1Button"
};
navigateBtn.Clicked += NavigateBtn_Clicked;

Content = new VerticalStackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = { navigateBtn }
};
}

private async void NavigateBtn_Clicked(object sender, EventArgs e)
{
await Shell.Current.GoToAsync($"//{nameof(Issue10509Page2)}?{Issue10509Page2.NavigationDataParam}=Passed");
}
}

[QueryProperty(nameof(NavigationData), NavigationDataParam)]
public class Issue10509Page2 : ContentPage
{
public const string NavigationDataParam = "NavigationDataParam";

private Label dataLabel;

public Issue10509Page2()
{
dataLabel = new Label
{
AutomationId = "Page2Label",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center
};

Content = new VerticalStackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = { dataLabel }
};
}

public string NavigationData { get; set; }

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);
dataLabel.Text = $"Navigation data: {NavigationData ?? "Missed"}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue10509 : _IssuesUITest
{
public Issue10509(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "Query parameter is missing after navigation";

[Test]
[Category(UITestCategories.Shell)]
public void QueryIsPassedOnNavigation()
{
App.WaitForElement("Page1Button");
App.Tap("Page1Button");
var label = App.WaitForElement("Page2Label");
Assert.That(label.GetText(), Is.EqualTo("Navigation data: Passed"));
}
}