Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fix additional scenarios with nested defined routes #13648

Merged
merged 5 commits into from
Feb 9, 2021
Merged

Conversation

PureWeen
Copy link
Contributor

@PureWeen PureWeen commented Feb 4, 2021

Description of Change

When defining routes like so

			Routing.RegisterRoute("page1/page2", typeof(ShellTestPage));
			Routing.RegisterRoute("page1/page2/page3", typeof(TestPage1));
			var shell = new TestShell(
				CreateShellItem(shellSectionRoute: "page1")
			);

Shell wasn't correctly collapsing page1 from the shellsectionroute into the global route because of the default route set on the Content

Issues Resolved

Platforms Affected

  • Core/XAML (all platforms)

Testing Procedure

  • Unit tests included to match reported issue
  • download the repro from the referenced issue and make sure nugets work as expected

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@PureWeen PureWeen requested review from rachelkang and removed request for StephaneDelcroix February 4, 2021 01:16
@@ -245,21 +249,6 @@ internal static List<RouteRequestBuilder> GenerateRoutePaths(Shell shell, Uri re

var segments = RetrievePaths(localPath);

if (!relativeMatch)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code just moved to the bottom of this method so we can try to fulfill the route before throwing an exception

@@ -221,11 +230,6 @@ internal static List<RouteRequestBuilder> GenerateRoutePaths(Shell shell, Uri re
var routeKeys = Routing.GetRouteKeys();
for (int i = 0; i < routeKeys.Length; i++)
{
if (routeKeys[i] == originalRequest.OriginalString)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code just moved to the bottom of this method so we can try to match all the nested route parts

@@ -274,124 +263,207 @@ internal static List<RouteRequestBuilder> GenerateRoutePaths(Shell shell, Uri re

if (relativeMatch && shell?.CurrentItem != null)
{
// retrieve current location
var currentLocation = NodeLocation.Create(shell);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code all just moved into a specific method ProcessRelativeRoute

@PureWeen
Copy link
Contributor Author

PureWeen commented Feb 8, 2021

# Conflicts:
#	Xamarin.Forms.Core.UnitTests/ShellNavigatingTests.cs
@PureWeen
Copy link
Contributor Author

PureWeen commented Feb 9, 2021

Test failures unrelated

shell.CurrentItem.CurrentItem.CurrentItem.Route,
};

restOfPath = CollapsePath(restOfPath.ToArray(), shellRoutes, true);
Copy link
Contributor Author

@PureWeen PureWeen Feb 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New Code

This code takes into account the parts of the shell route that need to be combined with the page routes which was the main issue.

So if the shell route is

//default_item/page/default_content

and the user registers a global route of

page/page2

When they navigate to //page/page2 the uri should ne

//page/page2


bestMatches.Clear();
ExpandOutGlobalRoutes(possibleRoutePaths, routeKeys);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new code

The ExpandOutGlobalRoutes used to just be inside the if statement for relative route searches but I moved the logic out to ExpandOutGlobalRoutes so if the user supplies an absolute route it can still try to expand out the global routes

var url = possibleRoutePath.PathFull;

var globalRouteMatches =
SearchForGlobalRoutes(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new code

Same description as above. Once we get here if the full route hasn't been matched then we try to fulfill the rest of the request with global registered routes.

int walkBackCurrentStackIndex = -1;

if (paths.Count > 0)
walkBackCurrentStackIndex = localRouteStack.IndexOf(paths[0]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new code

The idea here is to collapse the URI

If a user is at

//monkey/page/nextpage

And they have a global route that's

page/nextpage/something

Then this code will combine those two paths so they become

//monkey/page/something

Copy link
Contributor

@rachelkang rachelkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes issue referenced and LGTM for the most part!
Thank you for all the PR comments :)
Just had a few nit questions/suggestions

Xamarin.Forms.Core.UnitTests/ShellNavigatingTests.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shell/ShellUriHandler.cs Show resolved Hide resolved
Xamarin.Forms.Core/Shell/ShellUriHandler.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shell/ShellUriHandler.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shell/ShellUriHandler.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shell/ShellUriHandler.cs Outdated Show resolved Hide resolved
@PureWeen PureWeen merged commit cc0caa6 into 5.0.0 Feb 9, 2021
@PureWeen PureWeen deleted the fix_13611 branch February 9, 2021 18:12
@samhouts samhouts added this to the 5.0.0 milestone Feb 12, 2021
@samhouts samhouts added 5.0.0 Regression on 5.0.0 t/bug 🐛 labels Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] [Shell] [iOS] [Android] Shell Navigation (via RegisterRoute) behaves differently in 5.0
5 participants