Skip to content

Commit

Permalink
feat: add experimental alternateLinkCanonicalQueries property
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Feb 4, 2025
1 parent 164e5da commit e2df557
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const DEFAULT_OPTIONS = {
autoImportTranslationFunctions: false,
typedPages: true,
typedOptionsAndMessages: false,
generatedLocaleFilePathFormat: 'absolute'
generatedLocaleFilePathFormat: 'absolute',
alternateLinkCanonicalQueries: false
},
bundle: {
compositionOnly: true,
Expand Down
9 changes: 8 additions & 1 deletion src/runtime/routing/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ export function getHreflangLinks(
localeMap.set(localeLanguage, locale)
}

const routeWithoutQuery = common.router.resolve({ query: {} })
const strictCanonicals = common.runtimeConfig.public.i18n.experimental.alternateLinkCanonicalQueries === true
const routeWithoutQuery = strictCanonicals ? common.router.resolve({ query: {} }) : undefined

// set meta property which is lost on router.resolve
if (!common.runtimeConfig.public.i18n.experimental.switchLocalePathLinkSSR && strictCanonicals) {
routeWithoutQuery!.meta = common.router.currentRoute.value.meta
}

for (const [language, mapLocale] of localeMap.entries()) {
const localePath = switchLocalePath(common, mapLocale.code, routeWithoutQuery)
const canonicalQueryParams = getCanonicalQueryParams(common, seo)
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ export interface ExperimentalFeatures {
* @remark `'relative'` locale file and langDir paths are converted to be relative to the `rootDir`
*/
generatedLocaleFilePathFormat?: 'absolute' | 'relative'

/**
* Removes non-canonical query parameters from alternate link meta tags
*
* @defaultValue `false`
*/
alternateLinkCanonicalQueries?: boolean
}

export interface BundleOptions
Expand Down

0 comments on commit e2df557

Please sign in to comment.