From ae9c07feb8377fe6c989141e253b205b6d7697c7 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Mon, 9 Dec 2024 15:44:05 +0000 Subject: [PATCH] fix: Navigate once when starting app with same route as navigated --- .../FrameworkElementExtensions.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Uno.Extensions.Navigation.UI/FrameworkElementExtensions.cs b/src/Uno.Extensions.Navigation.UI/FrameworkElementExtensions.cs index 92d75cf747..8fffe04046 100644 --- a/src/Uno.Extensions.Navigation.UI/FrameworkElementExtensions.cs +++ b/src/Uno.Extensions.Navigation.UI/FrameworkElementExtensions.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace Uno.Extensions.Navigation; +namespace Uno.Extensions.Navigation; public static class FrameworkElementExtensions { @@ -35,11 +33,12 @@ public static Task HostAsync( { var initialNavigation = () => nav.NavigateRouteAsync(root, initialRoute ?? string.Empty); + Route? launchRoute = default; var start = () => Task.CompletedTask; var hostConfigOptions = sp.GetService>(); if (hostConfigOptions?.Value is { } hostConfig && - hostConfig.LaunchRoute() is { } launchRoute && - launchRoute.IsEmpty() == false) + (launchRoute = hostConfig.LaunchRoute()) is { } && + !launchRoute.IsEmpty()) { start = () => nav.NavigateRouteAsync(root, launchRoute.FullPath()); } @@ -57,8 +56,13 @@ public static Task HostAsync( } var fullstart = async () => { - await initialNavigation(); - await start(); + var response = await initialNavigation(); + + if (launchRoute is null || + !launchRoute.FullPath().Equals(response?.Route?.FullPath())) + { + await start(); + } }; var startupTask = elementRegion.Services!.Startup(fullstart); return startupTask;