@@ -103,7 +103,8 @@ describe.each([{basePath: undefined}, {basePath: '/base'}])(
103
103
routing,
104
104
request : getMockRequest ( 'https://example.com/' ) ,
105
105
resolvedLocale : 'en' ,
106
- localizedPathnames : pathnames [ '/' ]
106
+ localizedPathnames : pathnames [ '/' ] ,
107
+ internalTemplateName : '/'
107
108
} ) . split ( ', ' )
108
109
) . toEqual ( [
109
110
`<https://example.com${
@@ -120,7 +121,8 @@ describe.each([{basePath: undefined}, {basePath: '/base'}])(
120
121
routing,
121
122
request : getMockRequest ( 'https://example.com/about' ) ,
122
123
resolvedLocale : 'en' ,
123
- localizedPathnames : pathnames [ '/about' ]
124
+ localizedPathnames : pathnames [ '/about' ] ,
125
+ internalTemplateName : '/about'
124
126
} ) . split ( ', ' )
125
127
) . toEqual ( [
126
128
`<https://example.com${ basePath } /about>; rel="alternate"; hreflang="en"` ,
@@ -133,7 +135,8 @@ describe.each([{basePath: undefined}, {basePath: '/base'}])(
133
135
routing,
134
136
request : getMockRequest ( 'https://example.com/de/ueber' ) ,
135
137
resolvedLocale : 'de' ,
136
- localizedPathnames : pathnames [ '/about' ]
138
+ localizedPathnames : pathnames [ '/about' ] ,
139
+ internalTemplateName : '/about'
137
140
} ) . split ( ', ' )
138
141
) . toEqual ( [
139
142
`<https://example.com${ basePath } /about>; rel="alternate"; hreflang="en"` ,
@@ -146,7 +149,8 @@ describe.each([{basePath: undefined}, {basePath: '/base'}])(
146
149
routing,
147
150
request : getMockRequest ( 'https://example.com/users/2' ) ,
148
151
resolvedLocale : 'en' ,
149
- localizedPathnames : pathnames [ '/users/[userId]' ]
152
+ localizedPathnames : pathnames [ '/users/[userId]' ] ,
153
+ internalTemplateName : '/users/[userId]'
150
154
} ) . split ( ', ' )
151
155
) . toEqual ( [
152
156
`<https://example.com${ basePath } /users/2>; rel="alternate"; hreflang="en"` ,
@@ -155,6 +159,35 @@ describe.each([{basePath: undefined}, {basePath: '/base'}])(
155
159
] ) ;
156
160
} ) ;
157
161
162
+ it ( 'works for partial pathnames with undefined entries' , ( ) => {
163
+ const routing = receiveRoutingConfig ( {
164
+ defaultLocale : 'en' ,
165
+ locales : [ 'en' , 'de' , 'ja' ] ,
166
+ localePrefix : 'as-needed'
167
+ } ) ;
168
+ const pathnames = {
169
+ '/' : '/' ,
170
+ '/about' : {
171
+ de : '/ueber'
172
+ }
173
+ } ;
174
+
175
+ expect (
176
+ getAlternateLinksHeaderValue ( {
177
+ routing,
178
+ request : getMockRequest ( 'https://example.com/about' ) ,
179
+ resolvedLocale : 'en' ,
180
+ localizedPathnames : pathnames [ '/about' ] ,
181
+ internalTemplateName : '/about'
182
+ } ) . split ( ', ' )
183
+ ) . toEqual ( [
184
+ `<https://example.com${ basePath } /about>; rel="alternate"; hreflang="en"` ,
185
+ `<https://example.com${ basePath } /de/ueber>; rel="alternate"; hreflang="de"` ,
186
+ `<https://example.com${ basePath } /ja/about>; rel="alternate"; hreflang="ja"` ,
187
+ `<https://example.com${ basePath } /about>; rel="alternate"; hreflang="x-default"`
188
+ ] ) ;
189
+ } ) ;
190
+
158
191
it ( 'works for prefixed routing (always)' , ( ) => {
159
192
const routing = receiveRoutingConfig ( {
160
193
defaultLocale : 'en' ,
@@ -404,25 +437,29 @@ describe.each([{basePath: undefined}, {basePath: '/base'}])(
404
437
routing,
405
438
request : getMockRequest ( 'https://en.example.com/about' ) ,
406
439
resolvedLocale : 'en' ,
407
- localizedPathnames : routing . pathnames ! [ '/about' ]
440
+ localizedPathnames : routing . pathnames ! [ '/about' ] ,
441
+ internalTemplateName : '/about'
408
442
} ) ,
409
443
getAlternateLinksHeaderValue ( {
410
444
routing,
411
445
request : getMockRequest ( 'https://ca.example.com/about' ) ,
412
446
resolvedLocale : 'en' ,
413
- localizedPathnames : routing . pathnames ! [ '/about' ]
447
+ localizedPathnames : routing . pathnames ! [ '/about' ] ,
448
+ internalTemplateName : '/about'
414
449
} ) ,
415
450
getAlternateLinksHeaderValue ( {
416
451
routing,
417
452
request : getMockRequest ( 'https://ca.example.com/fr/a-propos' ) ,
418
453
resolvedLocale : 'fr' ,
419
- localizedPathnames : routing . pathnames ! [ '/about' ]
454
+ localizedPathnames : routing . pathnames ! [ '/about' ] ,
455
+ internalTemplateName : '/about'
420
456
} ) ,
421
457
getAlternateLinksHeaderValue ( {
422
458
routing,
423
459
request : getMockRequest ( 'https://fr.example.com/a-propos' ) ,
424
460
resolvedLocale : 'fr' ,
425
- localizedPathnames : routing . pathnames ! [ '/about' ]
461
+ localizedPathnames : routing . pathnames ! [ '/about' ] ,
462
+ internalTemplateName : '/about'
426
463
} )
427
464
]
428
465
. map ( ( links ) => links . split ( ', ' ) )
@@ -440,25 +477,29 @@ describe.each([{basePath: undefined}, {basePath: '/base'}])(
440
477
routing,
441
478
request : getMockRequest ( 'https://en.example.com/users/42' ) ,
442
479
resolvedLocale : 'en' ,
443
- localizedPathnames : routing . pathnames ! [ '/users/[userId]' ]
480
+ localizedPathnames : routing . pathnames ! [ '/users/[userId]' ] ,
481
+ internalTemplateName : '/users/[userId]'
444
482
} ) ,
445
483
getAlternateLinksHeaderValue ( {
446
484
routing,
447
485
request : getMockRequest ( 'https://ca.example.com/users/42' ) ,
448
486
resolvedLocale : 'en' ,
449
- localizedPathnames : routing . pathnames ! [ '/users/[userId]' ]
487
+ localizedPathnames : routing . pathnames ! [ '/users/[userId]' ] ,
488
+ internalTemplateName : '/users/[userId]'
450
489
} ) ,
451
490
getAlternateLinksHeaderValue ( {
452
491
routing,
453
492
request : getMockRequest ( 'https://ca.example.com/fr/utilisateurs/42' ) ,
454
493
resolvedLocale : 'fr' ,
455
- localizedPathnames : routing . pathnames ! [ '/users/[userId]' ]
494
+ localizedPathnames : routing . pathnames ! [ '/users/[userId]' ] ,
495
+ internalTemplateName : '/users/[userId]'
456
496
} ) ,
457
497
getAlternateLinksHeaderValue ( {
458
498
routing,
459
499
request : getMockRequest ( 'https://fr.example.com/utilisateurs/42' ) ,
460
500
resolvedLocale : 'fr' ,
461
- localizedPathnames : routing . pathnames ! [ '/users/[userId]' ]
501
+ localizedPathnames : routing . pathnames ! [ '/users/[userId]' ] ,
502
+ internalTemplateName : '/users/[userId]'
462
503
} )
463
504
]
464
505
. map ( ( links ) => links . split ( ', ' ) )
@@ -601,7 +642,8 @@ describe('trailingSlash: true', () => {
601
642
routing,
602
643
request : new NextRequest ( new URL ( 'https://example.com' + pathname ) ) ,
603
644
resolvedLocale : 'en' ,
604
- localizedPathnames : pathnames [ '/about' ]
645
+ localizedPathnames : pathnames [ '/about' ] ,
646
+ internalTemplateName : '/about'
605
647
} ) . split ( ', ' )
606
648
) . toEqual ( [
607
649
`<https://example.com/about/>; rel="alternate"; hreflang="en"` ,
@@ -618,7 +660,8 @@ describe('trailingSlash: true', () => {
618
660
routing,
619
661
request : new NextRequest ( new URL ( 'https://example.com' + pathname ) ) ,
620
662
resolvedLocale : 'en' ,
621
- localizedPathnames : pathnames [ '/' ]
663
+ localizedPathnames : pathnames [ '/' ] ,
664
+ internalTemplateName : '/'
622
665
} ) . split ( ', ' )
623
666
) . toEqual ( [
624
667
`<https://example.com/>; rel="alternate"; hreflang="en"` ,
0 commit comments