id
stringlengths
14
15
text
stringlengths
49
1.09k
source
stringlengths
46
101
467e2fc53597-3
// and dynamic routes are checked { source: '/:path*', destination: `https://my-old-site.com/:path*`, }, ], } }, } Good to know: rewrites in beforeFiles do not check the filesystem/dynamic routes immediately after matching a source, they continue until all beforeFiles hav...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-4
fallback rewrites are checked/applied, these are applied before rendering the 404 page and after dynamic routes/all static assets have been checked. If you use fallback: true/'blocking' in getStaticPaths, the fallback rewrites defined in your next.config.js will not be run. Rewrite parameters When using parameters in a...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-5
async rewrites() { return [ { source: '/docs/:path*', destination: '/:path*', // The :path parameter is used here so will not be automatically passed in the query }, ] }, } You can still pass the parameters manually in the query if one is already used in the destination by specifyi...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-6
// as shown above }, ] }, } Good to know: Static pages from Automatic Static Optimization or prerendering params from rewrites will be parsed on the client after hydration and provided in the query. Path Matching Path matches are allowed, for example /blog/:slug will match /blog/hello-world (no nested paths...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-7
async rewrites() { return [ { source: '/blog/:slug*', destination: '/news/:slug*', // Matched parameters can be used in the destination }, ] }, } Regex Path Matching To match a regex path you can wrap the regex in parenthesis after a parameter, for example /blog/:slug(\\d{1,}) will...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-8
}, ] }, } The following characters (, ), {, }, :, *, +, ? are used for regex path matching, so when used in the source as non-special values they must be escaped by adding \\ before them: next.config.js module.exports = { async rewrites() { return [ { // this will match `/english(default)/some...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-9
has and missing items can have the following fields: type: String - must be either header, cookie, host, or query. key: String - the key from the selected type to match against. value: String or undefined - the value to check for, if undefined any value will match. A regex like string can be used to capture a specific ...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-10
key: 'x-rewrite-me', }, ], destination: '/another-page', }, // if the header `x-rewrite-me` is not present, // this rewrite will be applied { source: '/:path*', missing: [ { type: 'header', key: 'x-rewrite-me', ...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-11
// use a named capture group e.g. (?<page>home) value: 'home', }, { type: 'cookie', key: 'authorized', value: 'true', }, ], destination: '/:path*/home', }, // if the header `x-authorized` is present and // co...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-12
{ source: '/:path*', has: [ { type: 'host', value: 'example.com', }, ], destination: '/another-page', }, ] }, } Rewriting to an external URL Examples Incremental adoption of Next.js Using Multiple Zones Rewrites allow you to rewrite...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-13
}, { source: '/blog/:slug', destination: 'https://example.com/blog/:slug', // Matched parameters can be used in the destination }, ] }, } If you're using trailingSlash: true, you also need to insert a trailing slash in the source parameter. If the destination server is also expecting a...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-14
}, ] }, } Incremental adoption of Next.js You can also have Next.js fall back to proxying to an existing website after checking all Next.js routes. This way you don't have to change the rewrites configuration when migrating more pages to Next.js next.config.js module.exports = { async rewrites() { return { ...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-15
async rewrites() { return [ { source: '/with-basePath', // automatically becomes /docs/with-basePath destination: '/another', // automatically becomes /docs/another }, { // does not add /docs to /without-basePath since basePath: false is set // Note: this can not be...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-16
next.config.js module.exports = { i18n: { locales: ['en', 'fr', 'de'], defaultLocale: 'en', }, async rewrites() { return [ { source: '/with-locale', // automatically handles all locales destination: '/another', // automatically passes the locale on }, { // d...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
467e2fc53597-17
{ // it's possible to match all locales even when locale: false is set source: '/:locale/api-alias/:path*', destination: '/api/:path*', locale: false, }, { // this gets converted to /(en|fr|de)/(.*) so will not match the top-level // `/` or `/fr` routes like /...
https://nextjs.org/docs/app/api-reference/next-config-js/rewrites
674f101b75a3-0
Runtime Config Good to know: This feature is considered legacy and does not work with Automatic Static Optimization, Output File Tracing, or React Server Components. Please use environment variables instead to avoid initialization overhead. To add runtime configuration to your app, open next.config.js and add the publi...
https://nextjs.org/docs/app/api-reference/next-config-js/runtime-configuration
674f101b75a3-1
Anything accessible to both client and server-side code should be under publicRuntimeConfig. A page that relies on publicRuntimeConfig must use getInitialProps or getServerSideProps or your application must have a Custom App with getInitialProps to opt-out of Automatic Static Optimization. Runtime configuration won't b...
https://nextjs.org/docs/app/api-reference/next-config-js/runtime-configuration
674f101b75a3-2
function MyImage() { return ( <div> <Image src={`${publicRuntimeConfig.staticFolder}/logo.png`} alt="logo" layout="fill" /> </div> ) } export default MyImage
https://nextjs.org/docs/app/api-reference/next-config-js/runtime-configuration
3c908699141c-0
serverComponentsExternalPackagesDependencies used inside Server Components and Route Handlers will automatically be bundled by Next.js. If a dependency is using Node.js specific features, you can choose to opt-out specific dependencies from the Server Components bundling and use native Node.js require. next.config.js /...
https://nextjs.org/docs/app/api-reference/next-config-js/serverComponentsExternalPackages
3c908699141c-1
@sentry/nextjs @sentry/node @swc/core argon2 autoprefixer aws-crt bcrypt better-sqlite3 canvas cpu-features cypress eslint express firebase-admin jest jsdom lodash mdx-bundler mongodb mongoose next-mdx-remote next-seo payload pg playwright postcss prettier prisma puppeteer rimraf sharp shiki sqlite3 tailwindcss ts-node...
https://nextjs.org/docs/app/api-reference/next-config-js/serverComponentsExternalPackages
81dc5b631b23-0
trailingSlash By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example /about/ will redirect to /about. You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes. O...
https://nextjs.org/docs/app/api-reference/next-config-js/trailingSlash
859f8a377ecb-0
transpilePackages Next.js can automatically transpile and bundle dependencies from local packages (like monorepos) or from external dependencies (node_modules). This replaces the next-transpile-modules package. next.config.js /** @type {import('next').NextConfig} */ const nextConfig = { transpilePackages: ['@acme/ui'...
https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages
beff6c4914e2-0
turbo (Experimental) Warning: These features are experimental and will only work with next --turbo. webpack loaders Currently, Turbopack supports a subset of webpack's loader API, allowing you to use some webpack loaders to transform code in Turbopack. To configure loaders, add the names of the loaders you've installed...
https://nextjs.org/docs/app/api-reference/next-config-js/turbo
beff6c4914e2-1
}, }, }, } Then, given the above configuration, you can use transformed code from your app: import MyDoc from './my-doc.mdx' export default function Home() { return <MyDoc /> } Resolve Alias Through next.config.js, Turbopack can be configured to modify module resolution through aliases, similar to webpack's ...
https://nextjs.org/docs/app/api-reference/next-config-js/turbo
beff6c4914e2-2
Turbopack also supports conditional aliasing through this field, similar to Node.js's conditional exports. At the moment only the browser condition is supported. In the case above, imports of the mocha module will be aliased to mocha/browser-entry.js when Turbopack targets browser environments. For more information and...
https://nextjs.org/docs/app/api-reference/next-config-js/turbo
8d7f8e5e9f61-0
typedRoutes (experimental)Experimental support for statically typed links. This feature requires using the App Router as well as TypeScript in your project. next.config.js /** @type {import('next').NextConfig} */ const nextConfig = { experimental: { typedRoutes: true, }, } module.exports = nextConfig
https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes
78b228e24dd5-0
typescript Next.js fails your production build (next build) when TypeScript errors are present in your project. If you'd like Next.js to dangerously produce production code even when your application has errors, you can disable the built-in type checking step. If disabled, be sure you are running type checks as part of...
https://nextjs.org/docs/app/api-reference/next-config-js/typescript
a4f8f241128b-0
urlImports URL imports are an experimental feature that allows you to import modules directly from external servers (instead of from the local disk). Warning: This feature is experimental. Only use domains that you trust to download and execute on your machine. Please exercise discretion, and caution until the feature ...
https://nextjs.org/docs/app/api-reference/next-config-js/urlImports
a4f8f241128b-1
URL Imports can be used everywhere normal package imports can be used. Security Model This feature is being designed with security as the top priority. To start, we added an experimental flag forcing you to explicitly allow the domains you accept URL imports from. We're working to take this further by limiting URL impo...
https://nextjs.org/docs/app/api-reference/next-config-js/urlImports
a4f8f241128b-2
One exception is resources that respond with Cache-Control: no-cache. These resources will have a no-cache entry in the lockfile and will always be fetched from the network on each build. Examples Skypack import confetti from 'https://cdn.skypack.dev/canvas-confetti' import { useEffect } from 'react' export default ...
https://nextjs.org/docs/app/api-reference/next-config-js/urlImports
a4f8f241128b-3
background: url('https://example.com/assets/hero.jpg'); } Asset Imports const logo = new URL('https://example.com/assets/file.txt', import.meta.url) console.log(logo.pathname) // prints "/_next/static/media/file.a9727b5d.txt"
https://nextjs.org/docs/app/api-reference/next-config-js/urlImports
6298ffd93b01-0
Custom Webpack Config Good to know: changes to webpack config are not covered by semver so proceed at your own risk Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case: CSS imports CSS modules Sass/SCSS imports Sass/SCSS modules preact Some c...
https://nextjs.org/docs/app/api-reference/next-config-js/webpack
6298ffd93b01-1
// Important: return the modified config return config }, } The webpack function is executed twice, once for the server and once for the client. This allows you to distinguish between client and server configuration using the isServer property. The second argument to the webpack function is an object with the fol...
https://nextjs.org/docs/app/api-reference/next-config-js/webpack
6298ffd93b01-2
// Example config for adding a loader that depends on babel-loader // This source was taken from the @next/mdx plugin source: // https://github.com/vercel/next.js/tree/canary/packages/next-mdx module.exports = { webpack: (config, options) => { config.module.rules.push({ test: /\.mdx/, use: [ o...
https://nextjs.org/docs/app/api-reference/next-config-js/webpack
a73144f3957d-0
webVitalsAttribution When debugging issues related to Web Vitals, it is often helpful if we can pinpoint the source of the problem. For example, in the case of Cumulative Layout Shift (CLS), we might want to know the first element that shifted when the single largest layout shift occurred. Or, in the case of Largest Co...
https://nextjs.org/docs/app/api-reference/next-config-js/webVitalsAttribution
a73144f3957d-1
next.config.js experimental: { webVitalsAttribution: ['CLS', 'LCP'] } Valid attribution values are all web-vitals metrics specified in the NextWebVitalsMetric type.
https://nextjs.org/docs/app/api-reference/next-config-js/webVitalsAttribution