Remove Base Path from the url
Unanswered
Beveren posted this in #help-forum
BeverenOP
We have added basePath in our next config file, it's all working fine in local/development env, but we have a requirement to remove the basePath in the production url. Is this even possible?
7 Replies
Toyger
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
basePath: isProd ? '' : '/your_dev_path',
}Hi, you can do that by checking if the environment is in production or development. Take a look at the example below:
const apiUrl = process.env.NEXT_PUBLIC_PROD_API_URL // https://somewhere.com
const devApiUrl = process.env.NEXT_PUBLIC_DEV_API_URL // localhost:3000
export const API_URL = process.env.NODE_ENV === "production" ? apiUrl : devApiUrlBeverenOP
thanks for the response!
We are running turborepo with 3 apps in a single domain, all of the 3 nextjs app has base path so that the cloudfront can know which apps send a request, but in production we want to remove the base-path, is it still possible?
I don't have prior knowledge of using turborepo but maybe the
Source: https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
rewrites function next.js would help you.const moduleExports = {
basePath: '/app',
async rewrites () {
return [
{
source: '/a/:path*',
destination: '/app/a/:path*',
},
]
},
};Source: https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
BeverenOP
is there a way to remove basePath on router.push("/path") ?
BeverenOP
bump