Skip to content

Commit 6fe1260

Browse files
authored
Add basePath documentation (#14882)
Fixes #14453
1 parent 55bfafc commit 6fe1260

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
description: Learn more about setting a base path in Next.js
3+
---
4+
5+
# Base Path
6+
7+
To deploy a Next.js application under a sub-path of a domain you can use the `basePath` option.
8+
9+
`basePath` allows you to set a path prefix for the application. For example `/docs` instead of `/` (the default).
10+
11+
For example, to set the base path to `/docs`, set the following configuration in `next.config.js`:
12+
13+
```js
14+
module.exports = {
15+
basePath: '/docs',
16+
}
17+
```
18+
19+
## Links
20+
21+
When linking to other pages using `next/link` and `next/router` the `basePath` will be automatically applied.
22+
23+
For example using `/about` will automatically become `/docs/about` when `basePath` is set to `/docs`.
24+
25+
```js
26+
export default function HomePage() {
27+
return (
28+
<>
29+
<Link href="/about">
30+
<a>About Page</a>
31+
</Link>
32+
</>
33+
)
34+
}
35+
```
36+
37+
Output html:
38+
39+
```html
40+
<a href="/docs/about">About Page</a>
41+
```
42+
43+
This makes sure that you don't have to change all links in your application when changing the `basePath` value.

docs/manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@
227227
"title": "Environment Variables",
228228
"path": "/docs/api-reference/next.config.js/environment-variables.md"
229229
},
230+
{
231+
"title": "Base Path",
232+
"path": "/docs/api-reference/next.config.js/basepath.md"
233+
},
230234
{
231235
"title": "Custom Page Extensions",
232236
"path": "/docs/api-reference/next.config.js/custom-page-extensions.md"

0 commit comments

Comments
 (0)