diff --git a/src/Controls/src/Core/Shell/ShellContent.cs b/src/Controls/src/Core/Shell/ShellContent.cs index d70fe0d38eac..abbb5bf4420a 100644 --- a/src/Controls/src/Core/Shell/ShellContent.cs +++ b/src/Controls/src/Core/Shell/ShellContent.cs @@ -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; } @@ -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; } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue10509.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue10509.cs new file mode 100644 index 000000000000..4335b0111402 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue10509.cs @@ -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"}"; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10509.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10509.cs new file mode 100644 index 000000000000..f24d7ea0aebe --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10509.cs @@ -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")); + } +} \ No newline at end of file