Unverified Commit 0e5a0ec4 authored by Matt DuLeone's avatar Matt DuLeone Committed by GitHub

Clear up rewrites documentation (#39238)



## Documentation / Examples

This PR specifically calls out in more clear language how the rewrites function behaves. This tripped me up recently as I recently came looking for more information, and the documentation left me with more questions than answers. This is an attempt to clear up the confusion I walked away with for anyone who comes in after me.

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent e3181c2d
...@@ -42,7 +42,7 @@ module.exports = { ...@@ -42,7 +42,7 @@ module.exports = {
Rewrites are applied to client-side routing, a `<Link href="/about">` will have the rewrite applied in the above example. Rewrites are applied to client-side routing, a `<Link href="/about">` will have the rewrite applied in the above example.
`rewrites` is an async function that expects an array to be returned holding objects with `source` and `destination` properties: `rewrites` is an async function that expects to return either an array or an object of arrays (see below) holding objects with `source` and `destination` properties:
- `source`: `String` - is the incoming request path pattern. - `source`: `String` - is the incoming request path pattern.
- `destination`: `String` is the path you want to route to. - `destination`: `String` is the path you want to route to.
...@@ -50,7 +50,7 @@ Rewrites are applied to client-side routing, a `<Link href="/about">` will have ...@@ -50,7 +50,7 @@ Rewrites are applied to client-side routing, a `<Link href="/about">` will have
- `locale`: `false` or `undefined` - whether the locale should not be included when matching. - `locale`: `false` or `undefined` - whether the locale should not be included when matching.
- `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties. - `has` is an array of [has objects](#header-cookie-and-query-matching) with the `type`, `key` and `value` properties.
Rewrites are applied after checking the filesystem (pages and `/public` files) and before dynamic routes by default. This behavior can be changed by returning an object instead of an array from the `rewrites` function since `v10.1` of Next.js: When the `rewrites` function returns an array, rewrites are applied after checking the filesystem (pages and `/public` files) and before dynamic routes. When the `rewrites` function returns an object of arrays with a specific shape, this behavior can be changed and more finely controlled, as of `v10.1` of Next.js:
```js ```js
module.exports = { module.exports = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment