Skip to content

Commit

Permalink
Add basePath documentation (#14882)
Browse files Browse the repository at this point in the history
Fixes #14453
  • Loading branch information
timneutkens authored Jul 6, 2020
1 parent 55bfafc commit 6fe1260
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/api-reference/next.config.js/basepath.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
description: Learn more about setting a base path in Next.js
---

# Base Path

To deploy a Next.js application under a sub-path of a domain you can use the `basePath` option.

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

For example, to set the base path to `/docs`, set the following configuration in `next.config.js`:

```js
module.exports = {
basePath: '/docs',
}
```

## Links

When linking to other pages using `next/link` and `next/router` the `basePath` will be automatically applied.

For example using `/about` will automatically become `/docs/about` when `basePath` is set to `/docs`.

```js
export default function HomePage() {
return (
<>
<Link href="/about">
<a>About Page</a>
</Link>
</>
)
}
```

Output html:

```html
<a href="/docs/about">About Page</a>
```

This makes sure that you don't have to change all links in your application when changing the `basePath` value.
4 changes: 4 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@
"title": "Environment Variables",
"path": "/docs/api-reference/next.config.js/environment-variables.md"
},
{
"title": "Base Path",
"path": "/docs/api-reference/next.config.js/basepath.md"
},
{
"title": "Custom Page Extensions",
"path": "/docs/api-reference/next.config.js/custom-page-extensions.md"
Expand Down

0 comments on commit 6fe1260

Please sign in to comment.