Q41: How does the basePath configuration option work in next.config.js?

basePath: '/docs' hosting allows serving a Next.js application under a URL sub-path instead of root domain paths. All <Link> components and asset paths automatically prepend the specified basePath prefix.

Setting basePath in next.config.js
// next.config.js
module.exports = {
  basePath: '/sub-app',
};
💡 Pages in pages/about.js are automatically served from /sub-app/about.
Key Takeaways
  • Configured via basePath: '/prefix' in next.config.js.
  • Prefixes all routes and internal links automatically.
Knowledge Check

If basePath: '/portal' is set, what URL corresponds to pages/settings.js?