[Shell] Fail when trying to add a duplicated route (#6613)
authorFelipe Momm <felipe.momm@gmail.com>
Tue, 25 Jun 2019 23:05:03 +0000 (20:05 -0300)
committerShane Neuville <shane94@hotmail.com>
Tue, 25 Jun 2019 23:05:03 +0000 (17:05 -0600)
Xamarin.Forms.Core.UnitTests/ShellTests.cs
Xamarin.Forms.Core/Routing.cs

index c4506fa..23ecae8 100644 (file)
@@ -129,6 +129,14 @@ namespace Xamarin.Forms.Core.UnitTests
                        Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute("app://tab2/IMPL_tab21", typeof(ShellItem)));
                }
 
+               [Test]
+               public async Task FailWhenAddingDuplicatedRouting()
+               {
+                       var route = "dogs";
+                       Routing.RegisterRoute(route, typeof(ShellItem));
+
+                       Assert.Catch(typeof(ArgumentException), () => Routing.RegisterRoute("dogs", typeof(ShellItem)));
+               }
 
                [Test]
                public async Task RelativeGoTo()
index 8ab67f4..8feecbf 100644 (file)
@@ -153,6 +153,9 @@ namespace Xamarin.Forms
                                if (IsImplicit(part))
                                        throw new ArgumentException($"Route contains invalid characters in \"{part}\"");
                        }
+
+                       if (CompareWithRegisteredRoutes(route))
+                               throw new ArgumentException($"Duplicated Route: \"{route}\"");
                }
 
                class TypeRouteFactory : RouteFactory