# gt-next: General Translation Next.js SDK: createNextMiddleware URL: https://generaltranslation.com/en-GB/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 lets you add a different route for each locale in your Next.js application. For example, a French user would be routed to `/fr/landing` and an English user would be routed 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 localised paths for your application. | | `localeRouting` | A flag that enables or disables i18n routing. | | `prefixDefaultLocale` | A flag that enables or disables removal of the locale prefix from the default locale. (e.g. `/en/about` -> `/about`) | | `ignoreSourceMaps` | A flag that enables or disables ignoring source maps. | *** ## Example ### Basic usage Add this function and the path matcher to your proxy file to enable locale routing. ```js title="proxy.ts" copy import { createNextMiddleware } from 'gt-next/middleware' export default createNextMiddleware(); export const config = { matcher: [ /* * Match all request paths except for those starting with: * - api (API routes) * - _next (internal files) * - static files */ "/((?!api|static|.*\\..*|_next).*)", ], } ``` ### Localised paths You can specify localised paths using the `pathConfig` option in the proxy file. ```js title="proxy.ts" 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="proxy.ts" copy export default createNextMiddleware({ prefixDefaultLocale: true, }); ``` When this is true, every path must be prefixed with the locale. If you set this to `false` (the default), only the default locale will be removed from the path. *** ## Notes * The `createNextMiddleware` function is a utility function that creates a proxy/middleware function for use with Next.js. Place it in `proxy.ts` in your project root. ## Next steps