-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix additional scenarios with nested defined routes #13648
Conversation
@@ -245,21 +249,6 @@ internal static List<RouteRequestBuilder> GenerateRoutePaths(Shell shell, Uri re | |||
|
|||
var segments = RetrievePaths(localPath); | |||
|
|||
if (!relativeMatch) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
# Conflicts: # Xamarin.Forms.Core.UnitTests/ShellNavigatingTests.cs
Test failures unrelated |
shell.CurrentItem.CurrentItem.CurrentItem.Route, | ||
}; | ||
|
||
restOfPath = CollapsePath(restOfPath.ToArray(), shellRoutes, true); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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
There was a problem hiding this 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
Description of Change
When defining routes like so
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
Testing Procedure
PR Checklist