-
Notifications
You must be signed in to change notification settings - Fork 26.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve rewrites documentation #34725
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7bb1c2
improve rewrite docs by adding example and docs for trailingSlash
Nutlope 6523ee5
removed extra code sample
Nutlope df21c17
added correct trailingSlash config
Nutlope a983072
updated wildcard to be * with a trailing slash
Nutlope 8d6900d
Update docs/api-reference/next.config.js/rewrites.md
Nutlope b54b0a2
Merge branch 'canary' into improve-rewrite-docs
kodiakhq[bot] 32f6b57
Merge branch 'canary' into improve-rewrite-docs
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
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 seems like a bug, wdyt @ijjk 🤔
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.
For context, I discovered that
:path*
doesn't catch trailing slashes so Davis came up with a wildcard expression that does.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.
We should be handling the trailing slash here
next.js/packages/next/lib/load-custom-routes.ts
Lines 72 to 73 in 1a0d149
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.
@ijjk yep! Here's a reproduction. Click on the "not working" demo link below, navigate to a specific blog post, then reload the page. It will redirect infinitely.
:path*
:path(.+)
If you want to take a look at the code, here are the full repos. They both have
trailingSlash: 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.
Oh it looks like the
destination
for this rewrite needs to end with a trailingSlash to match the other deployments expectation e.g. does changing it to the below resolve this?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.
I think documenting that the
destination
for a rewrite needs to honor the external destination's trailingSlash config makes senseThere 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.
Good catch, it works when you include a trailing slash for both the source and destination like this.
I'm assuming this is better than the
:path(.+)
wildcard so I just updated the PR to reflect that.