You sometimes want to deploy your Next JS under /blog
, /docs
, or /dashboard
folder. But by default, you can only deploy your Next JS on your project root folder.
Since Next JS 9.5, you can change this configuration by setting basePath
in your next.config.js
. By default, basePath
is set to /
but you can modify to /blog
or /docs
:
module.exports = {
basePath: '/docs',
};
That also means you can also run several Next JS applications under the same domain. You don't need to create a subdomain anymore.
After updating basePath
, you won't be able to visit http://localhost:3000
on your local development environment. To continue to browse on your local machine, you need to add basePath
value after http://localhost:3000
.
For your information, you don't need to update your links in your Next JS code. Indeed, it'll automatically prepend
basePath
value to all your links.
Browse our Next JS templates and themes that you can use for your Next JS project. Built on top of React in modular way, the templates use modern code pattern like component and UI blocks styled with Tailwind CSS. You can also check my portfolio:
Easy to configure and customize, you can modify the themes based on your needs. Saving you development and design time.