🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Routing••By Komal Nakrani

Fix: Manual i18n Routing Without a Middleware in Astro

Astro's manual i18n middleware error means i18n.routing is 'manual' but there is no src/middleware.ts. Add one that runs the astro:i18n middleware.

#Astro#Errors#i18n#Middleware

Astro throws “Enabled manual internationalization routing without having a middleware” when astro.config.mjs sets i18n.routing: 'manual' but the project has no middleware file. Manual routing turns off Astro’s built-in i18n middleware, so you must provide your own in src/middleware.ts, usually by exporting the middleware() helper from astro:i18n combined with your custom logic.

Key Takeaways

  • routing: 'manual' means Astro runs no i18n routing of its own.
  • Astro requires src/middleware.ts (or .js, or src/middleware/index.ts) in that mode.
  • The quickest fix is export const onRequest = middleware({ ... }) from astro:i18n.
  • Use sequence() to run your own logic before or after it.
  • If you do not need custom logic, switch back to the object form of routing.

The error

Enabled manual internationalization routing without having a middleware.
Your configuration setting `i18n.routing: 'manual'` requires you to provide your own i18n `middleware` file.

Why it happens

This config tells Astro you will handle locale routing yourself:

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'fr'],
    routing: 'manual',
  },
});

When Astro builds the middleware chain and finds no user middleware, it stops instead of silently serving pages with no i18n logic at all.

Fix: add a middleware file

Create src/middleware.ts and export Astro’s i18n middleware, with the options you would otherwise put in the config:

// src/middleware.ts
import { middleware } from 'astro:i18n';

export const onRequest = middleware({
  prefixDefaultLocale: true,
  redirectToDefaultLocale: false,
  fallbackType: 'redirect',
});

Restart astro dev after creating the file. The options follow the same rule as the config: redirectToDefaultLocale: true needs prefixDefaultLocale: true, or you get an invalid i18n middleware configuration error.

Add your own logic

The point of manual routing is to add exceptions. Wrap Astro’s handler and decide per request whether it runs:

// src/middleware.ts
import { middleware } from 'astro:i18n';
import { defineMiddleware } from 'astro:middleware';

const i18n = middleware({
  prefixDefaultLocale: true,
  redirectToDefaultLocale: false,
  fallbackType: 'redirect',
});

export const onRequest = defineMiddleware((context, next) => {
  // API routes and the health check skip locale handling.
  if (context.url.pathname.startsWith('/api/') || context.url.pathname === '/healthz') {
    return next();
  }
  return i18n(context, next);
});

To run extra middleware before or after it for every request, combine handlers with sequence() from astro:middleware. Our middleware guide explains ordering, and every middleware must return a Response (see middleware not a Response).

Or go back to automatic routing

If you set 'manual' by accident, use the object form and delete nothing else:

// astro.config.mjs (excerpt)
routing: {
  prefixDefaultLocale: true,
  redirectToDefaultLocale: false,
},

Astro then runs its own i18n middleware and no src/middleware.ts is needed. Our Astro i18n routing guide compares both modes, the Astro config docs cover the config file, and the official manual routing section has the full option list. If you add languages to a theme from the Astro themes catalog, automatic routing is usually enough.

FAQ

What does i18n routing manual do in Astro?

It disables Astro’s automatic i18n middleware so you can write your own routing logic, optionally reusing Astro’s via the middleware() helper from astro:i18n.

Where does the Astro middleware file go?

At src/middleware.ts or src/middleware.js, or as src/middleware/index.ts. It must export an onRequest function.

Can I use Astro i18n helpers without manual routing?

Yes. Helpers like getRelativeLocaleUrl() work in every routing mode. Manual routing is only needed when you want to change how requests are routed.