Fixes regression on routing priority for multi-layer index pages #10096
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
The sorting algorithm positions more specific routes before less specific routes, and considers index pages to be more specific than a dynamic route with a rest parameter inside of it.
This means that
/blog
is considered more specific than/blog/[...slug]
.But this special case was being applied incorrectly to indexes, which could cause a problem in scenarios like the following:
/
/blog
/blog/[...slug]
The algorithm would make the following comparisons:
/
is more specific than/blog
(incorrect)/blog/[...slug]
is more specific than/
(correct)/blog
is more specific than/blog/[...slug]
(correct)Although the incorrect first comparison is not a problem by itself, it could cause the algorithm to make the wrong decision.
Depending on the other routes in the project, the sorting could perform just the last two comparisons and by transitivity infer the inverse of the third (
/blog/[...slug
>/
>/blog
), which is incorrect.Now the algorithm doesn't have a special case for index pages and instead does the comparison soleley for rest parameter segments and their immediate parents, which is consistent with the transitivity property.
Testing
Docs
No docs changes expected :)