diff --git a/src/Uno.Extensions.Hosting.UI/AppHostingEnvironment.cs b/src/Uno.Extensions.Hosting.UI/AppHostingEnvironment.cs
index 083c8f6a1f..92e6336fb9 100644
--- a/src/Uno.Extensions.Hosting.UI/AppHostingEnvironment.cs
+++ b/src/Uno.Extensions.Hosting.UI/AppHostingEnvironment.cs
@@ -16,15 +16,14 @@ internal class AppHostingEnvironment : HostingEnvironment, IAppHostEnvironment,
public Assembly? HostAssembly { get; init; }
#if __WASM__
- public async Task UpdateAddressBar(Uri applicationUri)
+ public async Task UpdateAddressBar(Uri applicationUri, bool canGoBack)
{
CoreApplication.MainView?.DispatcherQueue.TryEnqueue(() =>
{
var state = 1;
if (PlatformHelper.IsWebAssembly)
{
- var currentView = SystemNavigationManager.GetForCurrentView();
- state = currentView?.AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible ? 1 : 0;
+ state = canGoBack ? 1 : 0;
}
var href = Imports.GetLocation();
diff --git a/src/Uno.Extensions.Hosting/IHasAddressBar.cs b/src/Uno.Extensions.Hosting/IHasAddressBar.cs
index 36a0b768ec..e4296ad6e0 100644
--- a/src/Uno.Extensions.Hosting/IHasAddressBar.cs
+++ b/src/Uno.Extensions.Hosting/IHasAddressBar.cs
@@ -12,8 +12,11 @@ public interface IHasAddressBar
///
/// The URI to update the address bar with.
///
+ ///
+ /// Whether it is possible to navigate back or not.
+ ///
///
/// A task that completes when the address bar has been updated.
///
- Task UpdateAddressBar(Uri applicationUri);
+ Task UpdateAddressBar(Uri applicationUri, bool canGoBack);
}
diff --git a/src/Uno.Extensions.Navigation.UI/BrowserAddressBarService.cs b/src/Uno.Extensions.Navigation.UI/BrowserAddressBarService.cs
index b911e7d820..a82683569a 100644
--- a/src/Uno.Extensions.Navigation.UI/BrowserAddressBarService.cs
+++ b/src/Uno.Extensions.Navigation.UI/BrowserAddressBarService.cs
@@ -72,12 +72,14 @@ private async void RouteChanged(object? sender, RouteChangedEventArgs e)
return;
}
+ var canGoBack = rootRegion.Navigator() is { } navigator && await navigator.CanGoBack();
+
var url = new UriBuilder
{
Query = route.Query(),
Path = route.FullPath()?.Replace("+", "/")
};
- await _addressbarHost!.UpdateAddressBar(url.Uri);
+ await _addressbarHost!.UpdateAddressBar(url.Uri, canGoBack);
}
catch (Exception ex)
{
diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml
index 8bc3db6f6b..a1175220ad 100644
--- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml
+++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml
@@ -1,14 +1,14 @@
+ Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
+ mc:Ignorable="d">
@@ -16,60 +16,61 @@
-
-
+
+
-
+
+ Click="OnePageToTwoPageCodebehindClick"
+ Content="Two (Codebehind)" />
+ Click="{x:Bind ViewModel.GoToTwo}"
+ Content="Two (ViewModel)" />
+ Click="{x:Bind ViewModel.SettingsWriteTest}"
+ Content="Settings Write Test" />
+
+
-
+
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+ HorizontalAlignment="Stretch"
+ HorizontalContentAlignment="Stretch"
+ VerticalContentAlignment="Stretch"
+ Style="{StaticResource FilledCardContentControlStyle}">
+
+
+
+
+
+
+
+
+
+
diff --git a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml.cs b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml.cs
index 2618a3d2bc..0389135fd3 100644
--- a/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml.cs
+++ b/testing/TestHarness/TestHarness.Shared/Ext/Navigation/PageNavigation/PageNavigationOnePage.xaml.cs
@@ -14,4 +14,22 @@ public async void OnePageToTwoPageCodebehindClick(object sender, RoutedEventArgs
await this.Navigator()!.NavigateViewAsync(this);
}
+
+ public async void GetUrlFromBrowser(object sender, RoutedEventArgs e)
+ {
+#if __WASM__
+ var url = Imports.GetLocation();
+
+ TxtUrl.Text = url;
+#else
+ TxtUrl.Text = "Not supported";
+#endif
+ }
+}
+#if __WASM__
+internal static partial class Imports
+{
+ [System.Runtime.InteropServices.JavaScript.JSImport("globalThis.Uno.Extensions.Hosting.getLocation")]
+ public static partial string GetLocation();
}
+#endif
diff --git a/testing/TestHarness/TestHarness.Shared/TestHarness.Shared.shproj b/testing/TestHarness/TestHarness.Shared/TestHarness.Shared.shproj
index 3e285b8a83..9cdd0da97a 100644
--- a/testing/TestHarness/TestHarness.Shared/TestHarness.Shared.shproj
+++ b/testing/TestHarness/TestHarness.Shared/TestHarness.Shared.shproj
@@ -4,6 +4,9 @@
6279c845-92f8-4333-ab99-3d213163593c
14.0
+
+ true
+
@@ -37,4 +40,4 @@
<_Globbled_Page Remove="Ext\Navigation\NavigationView\NavigationViewDataRecipeDetailsPage.xaml" />
<_Globbled_Page Remove="Ext\Navigation\NavigationView\NavigationViewDataRecipesPage.xaml" />
-
\ No newline at end of file
+
diff --git a/testing/TestHarness/TestHarness.UITest/Ext/Navigation/PageNavigation/Given_PageNavigation.cs b/testing/TestHarness/TestHarness.UITest/Ext/Navigation/PageNavigation/Given_PageNavigation.cs
index 01d26e418c..31e3db07f6 100644
--- a/testing/TestHarness/TestHarness.UITest/Ext/Navigation/PageNavigation/Given_PageNavigation.cs
+++ b/testing/TestHarness/TestHarness.UITest/Ext/Navigation/PageNavigation/Given_PageNavigation.cs
@@ -176,4 +176,27 @@ private void OnePageToFivePage()
App.WaitThenTap("FourPageToFivePageButton");
}
+
+ [Test]
+ [ActivePlatforms(Platform.Browser)]
+ public void When_PageNavigationNavigateRootUpdateUrl()
+ {
+ InitTestSection(TestSections.Navigation_PageNavigation);
+
+ App.WaitThenTap("ShowOnePageButton");
+
+ App.WaitThenTap("OnePageGetUrlFromBrowser");
+ App.WaitElement("OnePageTxtUrlFromBrowser");
+ var urlBefore = App.GetText("OnePageTxtUrlFromBrowser");
+
+ App.WaitThenTap("OnePageToTwoPageButton");
+
+ App.WaitThenTap("TwoPageBackButton");
+
+ App.WaitThenTap("OnePageGetUrlFromBrowser");
+ App.WaitElement("OnePageTxtUrlFromBrowser");
+ var urlAfter = App.GetText("OnePageTxtUrlFromBrowser");
+
+ Assert.AreEqual(urlBefore, urlAfter);
+ }
}