feat: add support for route groups#1563
Merged
Merged
Conversation
9020231 to
f27648f
Compare
Contributor
Author
|
oh no, looks like I broke some tests 🙈 |
ba618b1 to
b250f56
Compare
Contributor
Author
|
Alright, ready to review now 🎉 |
bartlomieju
approved these changes
Aug 1, 2023
bartlomieju
left a comment
Contributor
There was a problem hiding this comment.
LGTM, no comments. I love the approach of using a nominal type 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds support for route groups which allows you to use different layouts for routes in the same URL segment.
/routes /(marketing) /_layout.tsx <-- only applies to about.tsx and career.tsx /about.tsx /career.tsx /(info) /_layout.tsx <-- only applies to index.tsx and contact.tsx /index.tsx /contact.tsxTo be able to do this we need to keep track of the original route paths. Previously, matching
_layoutand_middlewarewas done via theirURLPattern, but this doesn't work with groups anymore. With groups multiple_layoutfiles can have the sameURLPatternand it becomes ambiguous as to which file to pick.To solve this we need to match on the original file path semantics instead of their resulting
URLPattern. To do that the PR adds an additional propertybaseRouteto each route which is the normalised file path. When a route matches we can retrieve that (like/foo/(bar)/(bob)/about) and easily match the needed layout files.The PR is a bit longer than I'd hoped. Most of the changes relate to changing the internal route signature from:
to
Instead of making
baseRoutejust a string, I made it a nominal type. Noticed that I ran into a couple of errors during development where some values started with a/, others didn't etc. With the nominal type we can force it to have been parsed first and ensure it always has the expected format.Fixes #1150 .