@@ -72,35 +72,28 @@ class NetlifyNextServer extends NextServer {
72
72
const { i18n } = this . nextConfig
73
73
const { routes, dynamicRoutes } = this . netlifyPrerenderManifest
74
74
75
- // matches static non-i18n routes
76
- const normalizedRoute = normalizeRoute ( route )
75
+ // matches static routes
76
+ const normalizedRoute = normalizeRoute ( i18n ? localizeRoute ( route , i18n ) : route )
77
77
if ( normalizedRoute in routes ) {
78
78
const { dataRoute } = routes [ normalizedRoute ]
79
- return [ route , dataRoute ]
80
- }
81
-
82
- // matches static i18n routes
83
- if ( i18n ) {
84
- const localizedRoute = localizeRoute ( normalizedRoute , i18n )
85
- if ( localizedRoute in routes ) {
86
- const dataRoute = localizeDataRoute ( routes [ localizedRoute ] . dataRoute , localizedRoute )
87
- return [ route , dataRoute ]
88
- }
79
+ const normalizedDataRoute = i18n ? localizeDataRoute ( dataRoute , normalizedRoute ) : dataRoute
80
+ return [ route , normalizedDataRoute ]
89
81
}
90
82
91
83
// matches dynamic routes
84
+ const unlocalizedRoute = i18n ? unlocalizeRoute ( normalizedRoute , i18n ) : normalizedRoute
92
85
for ( const dynamicRoute in dynamicRoutes ) {
93
- const unlocalizedRoute = i18n ? unlocalizeRoute ( normalizedRoute , i18n ) : normalizedRoute
94
- const matches = unlocalizedRoute . match ( dynamicRoutes [ dynamicRoute ] . routeRegex )
86
+ const { dataRoute , routeRegex } = dynamicRoutes [ dynamicRoute ]
87
+ const matches = unlocalizedRoute . match ( routeRegex )
95
88
if ( matches && matches . length !== 0 ) {
96
89
// remove the first match, which is the full route
97
90
matches . shift ( )
98
91
// replace the dynamic segments with the actual values
99
- const interpolatedDataRoute = dynamicRoutes [ dynamicRoute ] . dataRoute . replace ( / \[ ( .* ?) ] / g, ( ) => matches . shift ( ) )
100
- const dataRoute = i18n
101
- ? localizeDataRoute ( interpolatedDataRoute , localizeRoute ( normalizedRoute , i18n ) )
92
+ const interpolatedDataRoute = dataRoute . replace ( / \[ ( .* ?) ] / g, ( ) => matches . shift ( ) )
93
+ const normalizedDataRoute = i18n
94
+ ? localizeDataRoute ( interpolatedDataRoute , normalizedRoute )
102
95
: interpolatedDataRoute
103
- return [ route , dataRoute ]
96
+ return [ route , normalizedDataRoute ]
104
97
}
105
98
}
106
99
0 commit comments