Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
f8e44b94
Unverified
Commit
f8e44b94
authored
Jan 05, 2021
by
JJ Kasper
Committed by
GitHub
Jan 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add documentation for rewrite params query passing behavior (#20757)
Closes:
https://github.com/vercel/next.js/issues/20197
parent
873bf5dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
rewrites.md
docs/api-reference/next.config.js/rewrites.md
+50
-0
No files found.
docs/api-reference/next.config.js/rewrites.md
View file @
f8e44b94
...
@@ -39,6 +39,56 @@ module.exports = {
...
@@ -39,6 +39,56 @@ module.exports = {
-
`source`
is the incoming request path pattern.
-
`source`
is the incoming request path pattern.
-
`destination`
is the path you want to route to.
-
`destination`
is the path you want to route to.
## Rewrite parameters
When using parameters in a rewrite the parameters will be passed in the query by default when none of the parameters are used in the
`destination`
.
```
js
module
.
exports
=
{
async
rewrites
()
{
return
[
{
source
:
'/old-about/:path*'
,
destination
:
'/about'
,
// The :path parameter isn't used here so will be automatically passed in the query
},
]
},
}
```
If a parameter is used in the destination none of the parameters will be automatically passed in the query.
```
js
module
.
exports
=
{
async
rewrites
()
{
return
[
{
source
:
'/docs/:path*'
,
destination
:
'/:path*'
,
// The :path parameter is used here so will not be automatically passed in the query
},
]
},
}
```
You can still pass the parameters manually in the query if one is already used in the destination by specifying the query in the
`destination`
.
```
js
module
.
exports
=
{
async
rewrites
()
{
return
[
{
source
:
'/:first/:second'
,
destination
:
'/:first?second=:second'
,
// Since the :first parameter is used in the destination the :second parameter
// will not automatically be added in the query although we can manually add it
// as shown above
},
]
},
}
```
## Path Matching
## Path Matching
Path matches are allowed, for example
`/blog/:slug`
will match
`/blog/hello-world`
(no nested paths):
Path matches are allowed, for example
`/blog/:slug`
will match
`/blog/hello-world`
(no nested paths):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment