fix global routes to push onto stack correctly (#6025)
authorShane Neuville <shane94@hotmail.com>
Mon, 29 Apr 2019 23:40:12 +0000 (17:40 -0600)
committerSamantha Houts <samhouts@users.noreply.github.com>
Mon, 29 Apr 2019 23:40:11 +0000 (16:40 -0700)
fixes #6016

Xamarin.Forms.Core.UnitTests/ShellUriHandlerTests.cs
Xamarin.Forms.Core/Shell/Shell.cs
Xamarin.Forms.Core/Shell/ShellSection.cs

index 3ad5999..5a29947 100644 (file)
@@ -61,6 +61,26 @@ namespace Xamarin.Forms.Core.UnitTests
 
 
                [Test]
+               public async Task GlobalNavigateTwice()
+               {
+
+                       var shell = new Shell();
+                       var item1 = CreateShellItem(asImplicit: true, shellContentRoute: "rootlevelcontent1");
+
+                       shell.Items.Add(item1);
+                       Routing.RegisterRoute("cat", typeof(ContentPage));
+                       Routing.RegisterRoute("details", typeof(ContentPage));
+
+                       await shell.GoToAsync("cat");
+                       await shell.GoToAsync("details");
+
+                       Assert.AreEqual("app:///rootlevelcontent1/cat/details", shell.CurrentState.Location.ToString());
+                       await shell.GoToAsync("//rootlevelcontent1/details");
+                       Assert.AreEqual("app:///rootlevelcontent1/details", shell.CurrentState.Location.ToString());
+               }
+
+
+               [Test]
                public async Task GlobalRegisterAbsoluteMatching()      
                {
                        var shell = new Shell() { RouteScheme = "app", Route = "shellroute" };
index 5532102..cf49baa 100644 (file)
@@ -420,7 +420,7 @@ namespace Xamarin.Forms
                        }
                        else
                        {
-                               await CurrentItem.CurrentItem.GoToAsync(navigationRequest.Request.GlobalRoutes, queryData, animate);
+                               await CurrentItem.CurrentItem.GoToAsync(navigationRequest, queryData, animate);
                        }
                        
                        //if (Routing.CompareWithRegisteredRoutes(shellItemRoute))
index 41a5b8f..c1fd9c4 100644 (file)
@@ -75,13 +75,12 @@ namespace Xamarin.Forms
                        if (shellContent == null)
                                return Task.FromResult(true);
 
-                       
-                       if(request.Request.GlobalRoutes.Count > 0)
+                       if (request.Request.GlobalRoutes.Count > 0)
                        {
                                // TODO get rid of this hack and fix so if there's a stack the current page doesn't display
                                Device.BeginInvokeOnMainThread(async () =>
                                {
-                                       await GoToAsync(request.Request.GlobalRoutes, queryData, false);
+                                       await GoToAsync(request, queryData, false);
                                });
                        }
 
@@ -226,8 +225,9 @@ namespace Xamarin.Forms
                        return (ShellSection)(ShellContent)page;
                }
 
-               public virtual async Task GoToAsync(List<string> routes, IDictionary<string, string> queryData, bool animate)
+               internal async Task GoToAsync(NavigationRequest request, IDictionary<string, string> queryData, bool animate)
                {
+                       List<string> routes = request.Request.GlobalRoutes;
                        if (routes == null || routes.Count == 0)
                        {
                                await Navigation.PopToRootAsync(animate);
@@ -248,9 +248,12 @@ namespace Xamarin.Forms
                                                continue;
                                        }
 
-                                       while (_navStack.Count > i + 1)
+                                       if (request.StackRequest == NavigationRequest.WhatToDoWithTheStack.ReplaceIt)
                                        {
-                                               await OnPopAsync(false);
+                                               while (_navStack.Count > i + 1)
+                                               {
+                                                       await OnPopAsync(false);
+                                               }
                                        }
                                }