# gt-next: General Translation Next.js SDK: createNextMiddleware URL: https://generaltranslation.com/en-US/docs/next/api/middleware/create-next-middleware.mdx --- title: createNextMiddleware description: API reference for the createNextMiddleware() method --- ## Overview `createNextMiddleware` is a utility function that creates a middleware function for use with Next.js. It allows you to add a different route for each locale in your Next.js application. For example, a french user would be directed to `/fr/landing` and an english user would be directed to `/en/landing`. For more information on how to use this middleware, see the [i18n routing guide](/docs/next/guides/middleware). ## Reference ### Props ### Description | Prop | Description | |-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | `pathConfig` | A nested object that specifies localized paths for your application. | | `localeRouting` | A flag to enable or disable i18n routing. | | `prefixDefaultLocale` | A flag to enable or disable the removal of the locale prefix from the default locale. (e.g. `/en/about` -> `/about`) | | `ignoreSourceMaps` | A flag to enable or disable ignoring source maps. | --- ## Example ### Basic usage Just add this function and the path matcher to your middleware file to enable locale routing. ```js title="middleware.js" copy import { createNextMiddleware } from 'gt-next/middleware' export default createNextMiddleware(); export const config = { matcher: [ /* * Match all request paths except for the ones starting with: * - api (API routes) * - _next (internal files) * - static files */ "/((?!api|static|.*\\..*|_next).*)", ], } ``` ### Localized paths You can specify localized paths through the `pathConfig` option in the middleware file. ```js title="middleware.js" copy export default createNextMiddleware({ pathConfig: { "/about": "/about", "/airplanes": { "zh": "/飞机", } }, }); ``` See the [i18n routing guide](/docs/next/guides/middleware) for a detailed explanation of how this works. ### Remove default locale prefix You can remove the default locale prefix by setting the `prefixDefaultLocale` option to `false`. ```js title="middleware.js" copy export default createNextMiddleware({ prefixDefaultLocale: true, }); ``` When this is true, then every path must be prefixed with the locale. If you set this to `false` (which is the default), then only the default locale will be removed from the path. --- ## Notes * The `createNextMiddleware` function is a utility function that creates a middleware function for use with Next.js. ## Next steps