@@ -85,7 +85,7 @@ export function cmsRoute(options: CMSRouteOptions) {
85
85
return options . slug ;
86
86
}
87
87
const slugParam = options . slugParam || 'slug' ;
88
- return params [ slugParam ] || 'index' ;
88
+ return ( params [ slugParam ] || 'index' ) . replaceAll ( '/' , '--' ) ;
89
89
}
90
90
91
91
async function fetchData (
@@ -180,22 +180,22 @@ export function cmsRoute(options: CMSRouteOptions) {
180
180
res . setHeader ( 'cache-control' , 'private' ) ;
181
181
return ctx . render404 ( ) ;
182
182
}
183
+ const primaryDocId = `${ options . collection } /${ slug } ` ;
183
184
const mode = String ( req . query . preview ) === 'true' ? 'draft' : 'published' ;
184
185
const routeContext : CMSRouteContext = { req, slug, mode, cmsClient} ;
185
186
186
- const translationsTags = [ 'common' , ` ${ options . collection } / ${ slug } ` ] ;
187
- if ( options . translations ) {
188
- const tags = options . translations ( routeContext ) ?. tags || [ ] ;
189
- translationsTags . push ( ... tags ) ;
190
- }
187
+ const batchRequest = cmsClient . createBatchRequest ( {
188
+ mode ,
189
+ translate : true ,
190
+ } ) ;
191
+ batchRequest . addDoc ( primaryDocId ) ;
191
192
192
- const [ doc , translationsMap , data ] = await Promise . all ( [
193
- cmsClient . getDoc < CMSDoc > ( options . collection , slug , {
194
- mode,
195
- } ) ,
196
- cmsClient . loadTranslations ( { tags : translationsTags } ) ,
193
+ const [ batchRes , data ] = await Promise . all ( [
194
+ batchRequest . fetch ( ) ,
197
195
fetchData ( routeContext ) ,
198
196
] ) ;
197
+ const doc = batchRes . docs [ primaryDocId ] ;
198
+
199
199
if ( ! doc ) {
200
200
res . setHeader ( 'cache-control' , 'private' ) ;
201
201
return ctx . render404 ( ) ;
@@ -215,8 +215,19 @@ export function cmsRoute(options: CMSRouteOptions) {
215
215
req . get ( 'x-country-code' ) ||
216
216
req . get ( 'x-appengine-country' ) ||
217
217
null ;
218
- const translations = translationsForLocale ( translationsMap , locale ) ;
219
- let props : any = { ...data , req, locale, mode, slug, doc, country} ;
218
+
219
+ const i18nFallbacks = req . rootConfig . i18n ?. fallbacks || { } ;
220
+ const translationFallbackLocales = i18nFallbacks [ locale ] || [ locale ] ;
221
+ const translations = batchRes . getTranslations ( translationFallbackLocales ) ;
222
+ let props : any = {
223
+ ...data ,
224
+ req,
225
+ locale,
226
+ mode,
227
+ slug,
228
+ doc,
229
+ country,
230
+ } ;
220
231
if ( options . preRenderHook ) {
221
232
props = await options . preRenderHook ( props , routeContext ) ;
222
233
}
0 commit comments