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;