File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
api-reference/next.config.js Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments