Skip to content

Commit 6a69118

Browse files
committed
Merge branch 'add-route-events-types' of https://github.com/LauraBeatris/next.js into add-route-events-types
2 parents 1342c7e + a21e565 commit 6a69118

File tree

53 files changed

+304
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+304
-229
lines changed

docs/api-reference/next.config.js/basepath.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Learn more about setting a base path in Next.js
44

55
# Base Path
66

7+
> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out.
8+
79
To deploy a Next.js application under a sub-path of a domain you can use the `basePath` option.
810

911
`basePath` allows you to set a path prefix for the application. For example `/docs` instead of `/` (the default).

docs/api-reference/next.config.js/headers.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Add custom HTTP headers to your Next.js app.
44

55
# Headers
66

7+
> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out.
8+
79
Headers allow you to set custom HTTP headers for an incoming request path.
810

911
To set custom HTTP headers you can use the `headers` key in `next.config.js`:
@@ -90,6 +92,28 @@ module.exports = {
9092
}
9193
```
9294

95+
### Regex Path Matching
96+
97+
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:
98+
99+
```js
100+
module.exports = {
101+
async rewrites() {
102+
return [
103+
{
104+
source: '/blog/:post(\\d{1,})',
105+
headers: [
106+
{
107+
key: 'x-post',
108+
value: ':post',
109+
},
110+
],
111+
},
112+
]
113+
},
114+
}
115+
```
116+
93117
### Headers with basePath support
94118

95119
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with headers each `source` is automatically prefixed with the `basePath` unless you add `basePath: false` to the header:

docs/api-reference/next.config.js/redirects.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Add redirects to your Next.js app.
44

55
# Redirects
66

7+
> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out.
8+
79
Redirects allow you to redirect an incoming request path to a different destination path.
810

911
Redirects are only available on the Node.js environment and do not affect client-side routing.
@@ -66,6 +68,24 @@ module.exports = {
6668
}
6769
```
6870

71+
### Regex Path Matching
72+
73+
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:
74+
75+
```js
76+
module.exports = {
77+
async redirects() {
78+
return [
79+
{
80+
source: '/old-blog/:post(\\d{1,})',
81+
destination: '/blog/:post', // Matched parameters can be used in the destination
82+
permanent: false,
83+
},
84+
]
85+
},
86+
}
87+
```
88+
6989
### Redirects with basePath support
7090

7191
When leveraging [`basePath` support](/docs/api-reference/next.config.js/basepath.md) with redirects each `source` and `destination` is automatically prefixed with the `basePath` unless you add `basePath: false` to the redirect:

docs/api-reference/next.config.js/rewrites.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Add rewrites to your Next.js app.
44

55
# Rewrites
66

7+
> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out.
8+
79
<details open>
810
<summary><b>Examples</b></summary>
911
<ul>
@@ -69,6 +71,23 @@ module.exports = {
6971
}
7072
```
7173

74+
### Regex Path Matching
75+
76+
To match a regex path you can wrap the regex in parenthesis after a parameter, for example `/blog/:slug(\\d{1,})` will match `/blog/123` but not `/blog/abc`:
77+
78+
```js
79+
module.exports = {
80+
async rewrites() {
81+
return [
82+
{
83+
source: '/old-blog/:post(\\d{1,})',
84+
destination: '/blog/:post', // Matched parameters can be used in the destination
85+
},
86+
]
87+
},
88+
}
89+
```
90+
7291
## Rewriting to an external URL
7392

7493
<details>

docs/api-reference/next.config.js/trailing-slash.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Configure Next.js pages to resolve with or without a trailing slash
44

55
# Trailing Slash
66

7+
> This feature was introduced in [Next.js 9.5](https://nextjs.org/blog/next-9-5) and up. If you’re using older versions of Next.js, please upgrade before trying it out.
8+
79
By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example `/about/` will redirect to `/about`. You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes.
810

911
Open `next.config.js` and add the `trailingSlash` config:

docs/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ By using the DPS workflow, in addition to doing _code reviews_, you can do _depl
4040
For example, the [hybrid pages](/docs/basic-features/pages.md) approach is fully supported out of the box.
4141

4242
- Every page can either use [Static Generation](/docs/basic-features/pages.md#static-generation) or [Server-Side Rendering](/docs/basic-features/pages.md#server-side-rendering).
43-
- Pages that use [Static Generation](/docs/basic-features/pages.md#static-generation) and assets (JS, CSS, images, fonts, etc) will automatically be served from the [Vercel Smart CDN](https://vercel.com/smart-cdn), which is blazingly fast.
43+
- Pages that use [Static Generation](/docs/basic-features/pages.md#static-generation) and assets (JS, CSS, images, fonts, etc) will automatically be served from the [Vercel's Edge Network](https://vercel.com/docs/v2/edge-network/overview), which is blazingly fast.
4444
- Pages that use [Server-Side Rendering](/docs/basic-features/pages.md#server-side-rendering) and [API routes](/docs/api-routes/introduction.md) will automatically become isolated Serverless Functions. This allows page rendering and API requests to scale infinitely.
4545

4646
### Custom Domains, Environment Variables, Automatic HTTPS, and more

docs/getting-started.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ Open `package.json` and add the following `scripts`:
4141

4242
```json
4343
"scripts": {
44-
"dev": "next",
44+
"dev": "next dev",
4545
"build": "next build",
4646
"start": "next start"
4747
}
4848
```
4949

5050
These scripts refer to the different stages of developing an application:
5151

52-
- `dev` - Runs `next` which starts Next.js in development mode
53-
- `build` - Runs `next build` which builds the application for production usage
54-
- `start` - Runs `next start` which starts a Next.js production server
52+
- `dev` - Runs [`next dev`](/docs/api-reference/cli#development) which starts Next.js in development mode
53+
- `build` - Runs [`next build`](/docs/api-reference/cli#build) which builds the application for production usage
54+
- `start` - Runs [`next start`](/docs/api-reference/cli#production) which starts a Next.js production server
5555

56-
Next.js is built around the concept of pages. A page is a [React Component](https://reactjs.org/docs/components-and-props.html) exported from a `.js`, `.jsx`, `.ts`, or `.tsx` file in the `pages` directory.
56+
Next.js is built around the concept of [pages](/docs/basic-features/pages.md). A page is a [React Component](https://reactjs.org/docs/components-and-props.html) exported from a `.js`, `.jsx`, `.ts`, or `.tsx` file in the `pages` directory.
5757

5858
Pages are associated with a route based on their file name. For example `pages/about.js` is mapped to `/about`. You can even add dynamic route parameters with the filename.
5959

docs/routing/dynamic-routes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ The `query` objects are as follows:
108108
- `pages/post/[pid].js` - Will match `/post/1`, `/post/abc`, etc. But not `/post/create`
109109
- `pages/post/[...slug].js` - Will match `/post/1/2`, `/post/a/b/c`, etc. But not `/post/create`, `/post/abc`
110110
- Pages that are statically optimized by [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) will be hydrated without their route parameters provided, i.e `query` will be an empty object (`{}`).
111+
- When routing to a dynamic route using `Link` or `router`, you will need to specify the `href` as the dynamic route, for example `/post/[pid]` and `as` as the decorator for the URL, for example `/post/abc`.
111112

112113
After hydration, Next.js will trigger an update to your application to provide the route parameters in the `query` object.

errors/popstate-state-empty.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
#### Why This Error Occurred
44

5-
When using the browser back button the popstate event is triggered. Next.js sets
6-
`popstate` event triggered but `event.state` did not have `url` or `as`, causing a route change failure
5+
When using the browser back button the popstate event is triggered. Next.js sees a
6+
`popstate` event being triggered but `event.state` did not have `url` or `as`, causing a route change failure.
77

88
#### Possible Ways to Fix It
99

10-
The only known cause of this issue is manually manipulating `window.history` instead of using `next/router`
10+
The only known cause of this issue is manually manipulating `window.history` instead of using `next/router`. Starting from version 9.5, Next.js will ignore `popstate` events that contain `event.state` not created by its own router.
1111

1212
### Useful Links
1313

examples/auth0/.env.local.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Public Environment variables that can be used in the browser.
2+
NEXT_PUBLIC_AUTH0_CLIENT_ID=
3+
NEXT_PUBLIC_AUTH0_SCOPE="openid profile"
4+
NEXT_PUBLIC_AUTH0_DOMAIN=
5+
NEXT_PUBLIC_REDIRECT_URI="http://localhost:3000/api/callback"
6+
NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI="http://localhost:3000"
7+
8+
# Secret environment variables only available to Node.js
9+
AUTH0_CLIENT_SECRET=
10+
SESSION_COOKIE_SECRET=
11+
SESSION_COOKIE_LIFETIME=7200

0 commit comments

Comments
 (0)