diff --git a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs index 5113365005..b21a052447 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -134,6 +134,16 @@ public virtual async Task GoBackToAsync(string name, INavigat public virtual async Task GoBackAsync(INavigationParameters parameters) { await _semaphore.WaitAsync(); + + INavigationResult result = await GoBackInternalAsync(parameters); + + _semaphore.Release(); + + return result; + } + + private async Task GoBackInternalAsync(INavigationParameters parameters) + { Page page = null; try { @@ -174,7 +184,6 @@ public virtual async Task GoBackAsync(INavigationParameters p finally { NavigationSource = PageNavigationSource.Device; - _semaphore.Release(); } return Notify(NavigationRequestType.GoBack, parameters, GetGoBackException(page, GetPageFromWindow())); @@ -468,7 +477,7 @@ private Task RemoveAndGoBack(Page currentPage, string nextSegment, Queue RemovePagesFromNavigationPage(currentPage, pagesToRemove); - return GoBackAsync(parameters); + return GoBackInternalAsync(parameters); } private async Task RemoveAndPush(Page currentPage, string nextSegment, Queue segments, INavigationParameters parameters, bool? useModalNavigation, bool animated) diff --git a/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs b/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs index 52273ef6a1..2fbdac0ced 100644 --- a/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs +++ b/tests/Maui/Prism.DryIoc.Maui.Tests/Fixtures/Navigation/NavigationTests.cs @@ -83,6 +83,28 @@ public async Task RelativeNavigation_RemovesPage_AndNavigates() Assert.Equal(2, rootPage.Navigation.NavigationStack.Count); } + [Fact(Timeout = 5000)] + public async Task Issue3047_RelativeNavigation_RemovesPage_AndGoBack() + { + var mauiApp = CreateBuilder(prism => prism.CreateWindow("NavigationPage/MockViewA/MockViewB")) + .Build(); + var window = GetWindow(mauiApp); + + var rootPage = window.Page as NavigationPage; + Assert.NotNull(rootPage); + TestPage(rootPage); + var currentPage = rootPage.CurrentPage; + Assert.IsType(currentPage); + TestPage(currentPage); + var container = currentPage.GetContainerProvider(); + var navService = container.Resolve(); + Assert.Equal(2, rootPage.Navigation.NavigationStack.Count); + await navService.NavigateAsync("../"); + Assert.IsType(rootPage.CurrentPage); + TestPage(rootPage.CurrentPage); + Assert.Single(rootPage.Navigation.NavigationStack); + } + [Fact] public async Task AbsoluteNavigation_ResetsWindowPage() {