-
Notifications
You must be signed in to change notification settings - Fork 68
[i18n] non-default locales in sub-path-routing lacking redirects #108
Description
I came across a bug, where automatic redirects based on a non-default locale result in an HTTP status 404.
While the project builds just fine, it seems the i18n routes are not properly redirected using the _redirects file. They all end up in an HTTP status 404. The i18n-configuration in next.config.js is the following:
- locales:
[en, de] - defaultLocale:
en - use automatic sub-path-routing by default
The outcome after next build:
Page Size First Load JS
┌ λ / 3.09 kB 59.2 kB
├ └ css/f1d1aa362771dbbb9bf2.css 700 B
├ /_app 0 B 56.1 kB
├ λ /404 3.25 kB 59.4 kB
├ λ /api/graphql 0 B 56.1 kB
├ λ /api/manifest.json 0 B 56.1 kB
└ λ /stations/[station] 7.25 kB 63.4 kB
└ css/ab4ac78f55b7be8c2e88.css 1.6 kB
+ First Load JS shared by all 56.1 kB
├ chunks/435fbf78afb0ddecc1b360b3d2e1c38a37ed9942.cc35a6.js 21.9 kB
├ chunks/commons.799d26.js 9.78 kB
├ chunks/framework.432e4f.js 9.43 kB
├ chunks/main.8e2058.js 7.76 kB
├ chunks/pages/_app.c962df.js 5.78 kB
├ chunks/webpack.30ded3.js 1.47 kB
└ css/76c31999168d90a00cec.css 1.69 kB
λ (Lambda) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
(ISR) incremental static regeneration (uses revalidate in getStaticProps)
You see, there are a lot of getServerSideProps server-side rendered routes (mainly due to SEO information in <head>). The generated _redirects file by next-on-netlify is the following:
# Next-on-Netlify Redirects
/ /.netlify/functions/next_index 200
/_next/data/OHn0dZP5sVywVpIVkGiQG/index.json /.netlify/functions/next_index 200
/_next/data/OHn0dZP5sVywVpIVkGiQG/stations/:station.json /.netlify/functions/next_stations_station 200
/api/graphql /.netlify/functions/next_api_graphql 200
/api/manifest.json /.netlify/functions/next_api_manifestjson 200
/stations/:station /.netlify/functions/next_stations_station 200
So to have a proper route catching, the following redirects are missing IMO:
/en /.netlify/functions/next_index 200
/de /.netlify/functions/next_index 200
/en/stations/:station /.netlify/functions/next_stations_station 200
/de/stations/:station /.netlify/functions/next_stations_station 200
For SSG routes, it seems there is no 'fallback' redirect to the resulting default locale sub-path (e.g. /about ➡️ /en/about.html)
What I've already tried
Manually adding the mentioned /de & /en redirects above, but in case for /de, they end up in endless redirects. So I'm assuming there's some work needed in the template files as well...
Versions
- Next:
10.0.3 - next-on-netlify:
^2.6.3&github:netlify/next-on-netlify#ll/i18n
Related