vue-i18n-routing
Advanced tools
Comparing version
@@ -108,2 +108,8 @@ import type { Composer } from '@intlify/vue-i18n-bridge'; | ||
export declare const DefaultLocalizeRoutesPrefixable: typeof prefixable_2; | ||
export declare const DefaultPrefixable: typeof prefixable; | ||
export declare const DefaultSwitchLocalePathIntercepter: SwitchLocalePathIntercepter; | ||
/** | ||
@@ -124,3 +130,3 @@ * Direction | ||
export declare function extendI18n<TI18n extends I18n>(i18n: TI18n, { locales, localeCodes, baseUrl, hooks }?: VueI18nExtendOptions): EffectScope; | ||
export declare function extendI18n<TI18n extends I18n>(i18n: TI18n, { locales, localeCodes, baseUrl, hooks, context }?: VueI18nExtendOptions): EffectScope; | ||
@@ -225,3 +231,3 @@ export declare interface ExtendProperyDescripters { | ||
*/ | ||
export declare type I18nRoutingGlobalOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = Pick<I18nRoutingOptions<BaseUrl>, 'defaultLocale' | 'defaultDirection' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'routesNameSeparator' | 'strategy'> & { | ||
export declare type I18nRoutingGlobalOptions<Context = unknown> = Pick<I18nRoutingOptions<Context>, 'defaultLocale' | 'defaultDirection' | 'defaultLocaleRouteNameSuffix' | 'trailingSlash' | 'routesNameSeparator' | 'strategy' | 'prefixable' | 'switchLocalePathIntercepter'> & { | ||
localeCodes?: string[]; | ||
@@ -236,3 +242,3 @@ }; | ||
*/ | ||
export declare type I18nRoutingOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler> = { | ||
export declare type I18nRoutingOptions<Context = unknown> = { | ||
/** | ||
@@ -322,3 +328,3 @@ * Vue Router version | ||
*/ | ||
baseUrl?: string | BaseUrl; | ||
baseUrl?: string | BaseUrlResolveHandler<Context>; | ||
/** | ||
@@ -330,2 +336,20 @@ * Route options resolver | ||
routeOptionsResolver?: RouteOptionsResolver; | ||
/** | ||
* Whether to prefix the route path with the locale or not | ||
* | ||
* @defaultValue {@link DefaultPrefixable} | ||
*/ | ||
prefixable?: Prefixable; | ||
/** | ||
* An option that Intercepter for custom processing for paths resolved with {@link switchLocalePath} | ||
* | ||
* @defaultValue {@link DefaultSwitchLocalePathIntercepter} | ||
*/ | ||
switchLocalePathIntercepter?: SwitchLocalePathIntercepter; | ||
/** | ||
* Whether to prefix the localize route path with the locale or not | ||
* | ||
* @defaultValue {@link DefaultLocalizeRoutesPrefixable} | ||
*/ | ||
localizeRoutesPrefixable?: LocalizeRoutesPrefixable; | ||
} & RouterOptions; | ||
@@ -410,3 +434,3 @@ | ||
*/ | ||
export declare function localizeRoutes(routes: I18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, optionsResolver, locales }?: Pick<I18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix'> & { | ||
export declare function localizeRoutes(routes: I18nRoute[], { defaultLocale, strategy, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, includeUprefixedFallback, optionsResolver, localizeRoutesPrefixable, locales }?: Pick<I18nRoutingOptions, 'defaultLocale' | 'strategy' | 'locales' | 'routesNameSeparator' | 'trailingSlash' | 'defaultLocaleRouteNameSuffix' | 'localizeRoutesPrefixable'> & { | ||
includeUprefixedFallback?: boolean; | ||
@@ -416,4 +440,49 @@ optionsResolver?: RouteOptionsResolver; | ||
/** | ||
* Localize route path prefix judgment logic in {@link localizeRoutes} function | ||
*/ | ||
export declare type LocalizeRoutesPrefixable = (options: LocalizeRoutesPrefixableOptions) => boolean; | ||
/** | ||
* Localize route path prefix judgment options used in {@link LocalizeRoutesPrefixable} | ||
*/ | ||
export declare interface LocalizeRoutesPrefixableOptions { | ||
/** | ||
* Current locale | ||
*/ | ||
currentLocale: Locale; | ||
/** | ||
* Default locale | ||
*/ | ||
defaultLocale: Locale; | ||
/** | ||
* Curernt strategy | ||
*/ | ||
strategy: Strategies; | ||
/** | ||
* Whether the route to be resolved is child or not | ||
*/ | ||
isChild: boolean; | ||
/** | ||
* The path of route | ||
*/ | ||
path: string; | ||
} | ||
export declare type MetaAttrs = Record<string, any>; | ||
/** | ||
* Route path prefix judgment logic in {@link resolveRoute} function | ||
*/ | ||
export declare type Prefixable = (optons: PrefixableOptions) => boolean; | ||
declare function prefixable(optons: PrefixableOptions): boolean; | ||
declare function prefixable_2(optons: LocalizeRoutesPrefixableOptions): boolean; | ||
/** | ||
* Route path prefix judgment options used in {@link Prefixable} | ||
*/ | ||
export declare type PrefixableOptions = Pick<LocalizeRoutesPrefixableOptions, 'currentLocale' | 'defaultLocale' | 'strategy'>; | ||
export declare function proxyVueInstance(target: Function): Function; | ||
@@ -427,3 +496,3 @@ | ||
*/ | ||
export declare function registerGlobalOptions<BaseUrl extends BaseUrlResolveHandler = BaseUrlResolveHandler>(router: Router | VueRouter, options: I18nRoutingGlobalOptions<BaseUrl>): void; | ||
export declare function registerGlobalOptions<Context = unknown>(router: Router | VueRouter, options: I18nRoutingGlobalOptions<Context>): void; | ||
@@ -496,2 +565,4 @@ /** | ||
routesNameSeparator?: string; | ||
prefixable?: Prefixable; | ||
switchLocalePathIntercepter?: SwitchLocalePathIntercepter; | ||
} | ||
@@ -545,2 +616,7 @@ | ||
/** | ||
* The intercept handler which is called in {@link switchLocalePath} function | ||
*/ | ||
export declare type SwitchLocalePathIntercepter = (path: string, locale: Locale) => string; | ||
/** | ||
* The target locale info | ||
@@ -621,2 +697,3 @@ * | ||
localeCodes?: string[]; | ||
context?: unknown; | ||
hooks?: ExtendHooks; | ||
@@ -652,3 +729,6 @@ }; | ||
localeCodes: ComputedRef<string[]> | ||
__baseUrl: string | ||
/** | ||
* Base URL that is used in generating canonical links | ||
*/ | ||
baseUrl: ComputedRef<string> | ||
} | ||
@@ -655,0 +735,0 @@ declare module 'vue-i18n' { |
@@ -191,2 +191,9 @@ var VueI18nRouting = function(exports, vueDemi, VueRouter3, vueI18nBridge) { | ||
} | ||
function prefixable$1(optons) { | ||
const { currentLocale, defaultLocale, strategy, isChild, path } = optons; | ||
const isDefaultLocale = currentLocale === defaultLocale; | ||
const isChildWithRelativePath = isChild && !path.startsWith("/"); | ||
return !isChildWithRelativePath && !(isDefaultLocale && strategy === "prefix_except_default"); | ||
} | ||
const DefaultLocalizeRoutesPrefixable = prefixable$1; | ||
function localizeRoutes(routes, { | ||
@@ -200,2 +207,3 @@ defaultLocale = DEFAULT_LOCALE, | ||
optionsResolver = void 0, | ||
localizeRoutesPrefixable = DefaultLocalizeRoutesPrefixable, | ||
locales = [] | ||
@@ -272,3 +280,9 @@ } = {}) { | ||
const isChildWithRelativePath = isChild && !path.startsWith("/"); | ||
const shouldAddPrefix = !isChildWithRelativePath && !(isDefaultLocale && strategy === "prefix_except_default"); | ||
const shouldAddPrefix = localizeRoutesPrefixable({ | ||
isChild, | ||
path, | ||
currentLocale: locale, | ||
defaultLocale, | ||
strategy | ||
}); | ||
if (shouldAddPrefix) { | ||
@@ -313,3 +327,3 @@ path = `/${locale}${path}`; | ||
} | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL, hooks = {} } = {}) { | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL, hooks = {}, context = {} } = {}) { | ||
const scope = vueDemi.effectScope(); | ||
@@ -320,3 +334,3 @@ const orgInstall = i18n.install; | ||
const composer = getComposer(i18n); | ||
scope.run(() => extendComposer(composer, { locales, localeCodes, baseUrl, hooks })); | ||
scope.run(() => extendComposer(composer, { locales, localeCodes, baseUrl, hooks, context })); | ||
if (isVueI18n(i18n.global)) { | ||
@@ -355,8 +369,16 @@ extendVueI18n(i18n.global, hooks.onExtendVueI18n); | ||
function extendComposer(composer, options) { | ||
const { locales, localeCodes, baseUrl } = options; | ||
const { locales, localeCodes, baseUrl, context } = options; | ||
const _locales = vueDemi.ref(locales); | ||
const _localeCodes = vueDemi.ref(localeCodes); | ||
const _baseUrl = vueDemi.ref(""); | ||
composer.locales = vueDemi.computed(() => _locales.value); | ||
composer.localeCodes = vueDemi.computed(() => _localeCodes.value); | ||
composer.__baseUrl = resolveBaseUrl(baseUrl, {}); | ||
composer.baseUrl = vueDemi.computed(() => _baseUrl.value); | ||
vueDemi.watch( | ||
composer.locale, | ||
() => { | ||
_baseUrl.value = resolveBaseUrl(baseUrl, context); | ||
}, | ||
{ immediate: true } | ||
); | ||
if (options.hooks && options.hooks.onExtendComposer) { | ||
@@ -379,5 +401,5 @@ options.hooks.onExtendComposer(composer); | ||
}, | ||
__baseUrl: { | ||
baseUrl: { | ||
get() { | ||
return g.__baseUrl; | ||
return g.baseUrl.value; | ||
} | ||
@@ -408,5 +430,5 @@ } | ||
}, | ||
__baseUrl: { | ||
baseUrl: { | ||
get() { | ||
return composer.__baseUrl; | ||
return composer.baseUrl.value; | ||
} | ||
@@ -451,2 +473,5 @@ } | ||
routes, | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter, | ||
localizeRoutesPrefixable, | ||
routeOptionsResolver: optionsResolver | ||
@@ -465,2 +490,3 @@ } = asDefaultVueI18nRouterOptions(options); | ||
defaultLocaleRouteNameSuffix, | ||
localizeRoutesPrefixable, | ||
optionsResolver | ||
@@ -477,3 +503,5 @@ }); | ||
defaultLocaleRouteNameSuffix, | ||
defaultDirection | ||
defaultDirection, | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter | ||
}); | ||
@@ -532,3 +560,3 @@ router.beforeEach((to, from, next) => { | ||
function asDefaultVueI18nRouterOptions(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m; | ||
options.version = (_a = options.version) != null ? _a : 4; | ||
@@ -544,2 +572,5 @@ options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE; | ||
options.routes = (_j = options.routes) != null ? _j : []; | ||
options.prefixable = (_k = options.prefixable) != null ? _k : DefaultPrefixable; | ||
options.switchLocalePathIntercepter = (_l = options.switchLocalePathIntercepter) != null ? _l : DefaultSwitchLocalePathIntercepter; | ||
options.localizeRoutesPrefixable = (_m = options.localizeRoutesPrefixable) != null ? _m : DefaultLocalizeRoutesPrefixable; | ||
return options; | ||
@@ -554,3 +585,5 @@ } | ||
trailingSlash = DEFAULT_TRAILING_SLASH, | ||
localeCodes = [] | ||
localeCodes = [], | ||
prefixable: prefixable2 = DefaultPrefixable, | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter | ||
} = {}) { | ||
@@ -565,6 +598,14 @@ const options = getGlobalOptions(router); | ||
trailingSlash: proxy.trailingSlash || options.trailingSlash || trailingSlash, | ||
localeCodes: proxy.localeCodes || options.localeCodes || localeCodes | ||
localeCodes: proxy.localeCodes || options.localeCodes || localeCodes, | ||
prefixable: proxy.prefixable || options.prefixable || prefixable2, | ||
switchLocalePathIntercepter: proxy.switchLocalePathIntercepter || options.switchLocalePathIntercepter || switchLocalePathIntercepter | ||
}; | ||
} | ||
const RESOLVED_PREFIXED = /* @__PURE__ */ new Set(["prefix_and_default", "prefix_except_default"]); | ||
function prefixable(optons) { | ||
const { currentLocale, defaultLocale, strategy } = optons; | ||
const isDefaultLocale = currentLocale === defaultLocale; | ||
return !(isDefaultLocale && RESOLVED_PREFIXED.has(strategy)) && !(strategy === "no_prefix"); | ||
} | ||
const DefaultPrefixable = prefixable; | ||
function getRouteBaseName(givenRoute) { | ||
@@ -596,3 +637,3 @@ const router = this.router; | ||
const _locale = locale || getLocale(i18n); | ||
const { routesNameSeparator, defaultLocale, defaultLocaleRouteNameSuffix, strategy, trailingSlash } = getI18nRoutingOptions(router, this); | ||
const { routesNameSeparator, defaultLocale, defaultLocaleRouteNameSuffix, strategy, trailingSlash, prefixable: prefixable2 } = getI18nRoutingOptions(router, this); | ||
let _route = route; | ||
@@ -631,5 +672,3 @@ if (isString(route)) { | ||
} else { | ||
const isDefaultLocale = _locale === defaultLocale; | ||
const isPrefixed = !(isDefaultLocale && RESOLVED_PREFIXED.has(strategy)) && !(strategy === "no_prefix"); | ||
if (isPrefixed) { | ||
if (prefixable2({ currentLocale: _locale, defaultLocale, strategy })) { | ||
localizedRoute.path = `/${_locale}${localizedRoute.path}`; | ||
@@ -670,2 +709,3 @@ } | ||
} | ||
const DefaultSwitchLocalePathIntercepter = (path) => path; | ||
function switchLocalePath(locale) { | ||
@@ -690,3 +730,5 @@ const route = this.route; | ||
const baseRoute = assign({}, routeCopy, _baseRoute); | ||
const path = localePath.call(this, baseRoute, locale); | ||
let path = localePath.call(this, baseRoute, locale); | ||
const { switchLocalePathIntercepter } = getI18nRoutingOptions(this.router, this); | ||
path = switchLocalePathIntercepter(path, locale); | ||
return path; | ||
@@ -703,3 +745,3 @@ } | ||
}; | ||
if (i18n.locales == null || i18n.__baseUrl == null) { | ||
if (i18n.locales == null || i18n.baseUrl == null) { | ||
return metaObject; | ||
@@ -721,4 +763,4 @@ } | ||
} | ||
addHreflangLinks.call(this, locales, i18n.__baseUrl, metaObject.link, identifierAttribute); | ||
addCanonicalLinks.call(this, i18n.__baseUrl, metaObject.link, identifierAttribute, addSeoAttributes); | ||
addHreflangLinks.call(this, locales, vueDemi.unref(i18n.baseUrl), metaObject.link, identifierAttribute); | ||
addCanonicalLinks.call(this, vueDemi.unref(i18n.baseUrl), metaObject.link, identifierAttribute, addSeoAttributes); | ||
addCurrentOgLocale(currentLocale, currentLocaleIso, metaObject.meta, identifierAttribute); | ||
@@ -1020,3 +1062,3 @@ addAlternateOgLocales(locales, currentLocaleIso, metaObject.meta, identifierAttribute); | ||
} | ||
const VERSION = "0.3.0"; | ||
const VERSION = "0.4.0"; | ||
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; | ||
@@ -1029,2 +1071,5 @@ exports.DEFAULT_DETECTION_DIRECTION = DEFAULT_DETECTION_DIRECTION; | ||
exports.DEFAULT_TRAILING_SLASH = DEFAULT_TRAILING_SLASH; | ||
exports.DefaultLocalizeRoutesPrefixable = DefaultLocalizeRoutesPrefixable; | ||
exports.DefaultPrefixable = DefaultPrefixable; | ||
exports.DefaultSwitchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter; | ||
exports.STRATEGIES = STRATEGIES; | ||
@@ -1031,0 +1076,0 @@ exports.VERSION = VERSION; |
@@ -194,2 +194,9 @@ "use strict"; | ||
} | ||
function prefixable$1(optons) { | ||
const { currentLocale, defaultLocale, strategy, isChild, path } = optons; | ||
const isDefaultLocale = currentLocale === defaultLocale; | ||
const isChildWithRelativePath = isChild && !path.startsWith("/"); | ||
return !isChildWithRelativePath && !(isDefaultLocale && strategy === "prefix_except_default"); | ||
} | ||
const DefaultLocalizeRoutesPrefixable = prefixable$1; | ||
function localizeRoutes(routes, { | ||
@@ -203,2 +210,3 @@ defaultLocale = DEFAULT_LOCALE, | ||
optionsResolver = void 0, | ||
localizeRoutesPrefixable = DefaultLocalizeRoutesPrefixable, | ||
locales = [] | ||
@@ -275,3 +283,9 @@ } = {}) { | ||
const isChildWithRelativePath = isChild && !path.startsWith("/"); | ||
const shouldAddPrefix = !isChildWithRelativePath && !(isDefaultLocale && strategy === "prefix_except_default"); | ||
const shouldAddPrefix = localizeRoutesPrefixable({ | ||
isChild, | ||
path, | ||
currentLocale: locale, | ||
defaultLocale, | ||
strategy | ||
}); | ||
if (shouldAddPrefix) { | ||
@@ -316,3 +330,3 @@ path = `/${locale}${path}`; | ||
} | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL, hooks = {} } = {}) { | ||
function extendI18n(i18n, { locales = [], localeCodes = [], baseUrl = DEFAULT_BASE_URL, hooks = {}, context = {} } = {}) { | ||
const scope = vueDemi.effectScope(); | ||
@@ -323,3 +337,3 @@ const orgInstall = i18n.install; | ||
const composer = getComposer(i18n); | ||
scope.run(() => extendComposer(composer, { locales, localeCodes, baseUrl, hooks })); | ||
scope.run(() => extendComposer(composer, { locales, localeCodes, baseUrl, hooks, context })); | ||
if (isVueI18n(i18n.global)) { | ||
@@ -358,8 +372,16 @@ extendVueI18n(i18n.global, hooks.onExtendVueI18n); | ||
function extendComposer(composer, options) { | ||
const { locales, localeCodes, baseUrl } = options; | ||
const { locales, localeCodes, baseUrl, context } = options; | ||
const _locales = vueDemi.ref(locales); | ||
const _localeCodes = vueDemi.ref(localeCodes); | ||
const _baseUrl = vueDemi.ref(""); | ||
composer.locales = vueDemi.computed(() => _locales.value); | ||
composer.localeCodes = vueDemi.computed(() => _localeCodes.value); | ||
composer.__baseUrl = resolveBaseUrl(baseUrl, {}); | ||
composer.baseUrl = vueDemi.computed(() => _baseUrl.value); | ||
vueDemi.watch( | ||
composer.locale, | ||
() => { | ||
_baseUrl.value = resolveBaseUrl(baseUrl, context); | ||
}, | ||
{ immediate: true } | ||
); | ||
if (options.hooks && options.hooks.onExtendComposer) { | ||
@@ -382,5 +404,5 @@ options.hooks.onExtendComposer(composer); | ||
}, | ||
__baseUrl: { | ||
baseUrl: { | ||
get() { | ||
return g.__baseUrl; | ||
return g.baseUrl.value; | ||
} | ||
@@ -411,5 +433,5 @@ } | ||
}, | ||
__baseUrl: { | ||
baseUrl: { | ||
get() { | ||
return composer.__baseUrl; | ||
return composer.baseUrl.value; | ||
} | ||
@@ -454,2 +476,5 @@ } | ||
routes, | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter, | ||
localizeRoutesPrefixable, | ||
routeOptionsResolver: optionsResolver | ||
@@ -468,2 +493,3 @@ } = asDefaultVueI18nRouterOptions(options); | ||
defaultLocaleRouteNameSuffix, | ||
localizeRoutesPrefixable, | ||
optionsResolver | ||
@@ -480,3 +506,5 @@ }); | ||
defaultLocaleRouteNameSuffix, | ||
defaultDirection | ||
defaultDirection, | ||
prefixable: prefixable2, | ||
switchLocalePathIntercepter | ||
}); | ||
@@ -535,3 +563,3 @@ router.beforeEach((to, from, next) => { | ||
function asDefaultVueI18nRouterOptions(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m; | ||
options.version = (_a = options.version) != null ? _a : 4; | ||
@@ -547,2 +575,5 @@ options.defaultLocale = (_b = options.defaultLocale) != null ? _b : DEFAULT_LOCALE; | ||
options.routes = (_j = options.routes) != null ? _j : []; | ||
options.prefixable = (_k = options.prefixable) != null ? _k : DefaultPrefixable; | ||
options.switchLocalePathIntercepter = (_l = options.switchLocalePathIntercepter) != null ? _l : DefaultSwitchLocalePathIntercepter; | ||
options.localizeRoutesPrefixable = (_m = options.localizeRoutesPrefixable) != null ? _m : DefaultLocalizeRoutesPrefixable; | ||
return options; | ||
@@ -557,3 +588,5 @@ } | ||
trailingSlash = DEFAULT_TRAILING_SLASH, | ||
localeCodes = [] | ||
localeCodes = [], | ||
prefixable: prefixable2 = DefaultPrefixable, | ||
switchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter | ||
} = {}) { | ||
@@ -568,6 +601,14 @@ const options = getGlobalOptions(router); | ||
trailingSlash: proxy.trailingSlash || options.trailingSlash || trailingSlash, | ||
localeCodes: proxy.localeCodes || options.localeCodes || localeCodes | ||
localeCodes: proxy.localeCodes || options.localeCodes || localeCodes, | ||
prefixable: proxy.prefixable || options.prefixable || prefixable2, | ||
switchLocalePathIntercepter: proxy.switchLocalePathIntercepter || options.switchLocalePathIntercepter || switchLocalePathIntercepter | ||
}; | ||
} | ||
const RESOLVED_PREFIXED = /* @__PURE__ */ new Set(["prefix_and_default", "prefix_except_default"]); | ||
function prefixable(optons) { | ||
const { currentLocale, defaultLocale, strategy } = optons; | ||
const isDefaultLocale = currentLocale === defaultLocale; | ||
return !(isDefaultLocale && RESOLVED_PREFIXED.has(strategy)) && !(strategy === "no_prefix"); | ||
} | ||
const DefaultPrefixable = prefixable; | ||
function getRouteBaseName(givenRoute) { | ||
@@ -599,3 +640,3 @@ const router = this.router; | ||
const _locale = locale || getLocale(i18n); | ||
const { routesNameSeparator, defaultLocale, defaultLocaleRouteNameSuffix, strategy, trailingSlash } = getI18nRoutingOptions(router, this); | ||
const { routesNameSeparator, defaultLocale, defaultLocaleRouteNameSuffix, strategy, trailingSlash, prefixable: prefixable2 } = getI18nRoutingOptions(router, this); | ||
let _route = route; | ||
@@ -634,5 +675,3 @@ if (isString(route)) { | ||
} else { | ||
const isDefaultLocale = _locale === defaultLocale; | ||
const isPrefixed = !(isDefaultLocale && RESOLVED_PREFIXED.has(strategy)) && !(strategy === "no_prefix"); | ||
if (isPrefixed) { | ||
if (prefixable2({ currentLocale: _locale, defaultLocale, strategy })) { | ||
localizedRoute.path = `/${_locale}${localizedRoute.path}`; | ||
@@ -673,2 +712,3 @@ } | ||
} | ||
const DefaultSwitchLocalePathIntercepter = (path) => path; | ||
function switchLocalePath(locale) { | ||
@@ -693,3 +733,5 @@ const route = this.route; | ||
const baseRoute = assign({}, routeCopy, _baseRoute); | ||
const path = localePath.call(this, baseRoute, locale); | ||
let path = localePath.call(this, baseRoute, locale); | ||
const { switchLocalePathIntercepter } = getI18nRoutingOptions(this.router, this); | ||
path = switchLocalePathIntercepter(path, locale); | ||
return path; | ||
@@ -706,3 +748,3 @@ } | ||
}; | ||
if (i18n.locales == null || i18n.__baseUrl == null) { | ||
if (i18n.locales == null || i18n.baseUrl == null) { | ||
return metaObject; | ||
@@ -724,4 +766,4 @@ } | ||
} | ||
addHreflangLinks.call(this, locales, i18n.__baseUrl, metaObject.link, identifierAttribute); | ||
addCanonicalLinks.call(this, i18n.__baseUrl, metaObject.link, identifierAttribute, addSeoAttributes); | ||
addHreflangLinks.call(this, locales, vueDemi.unref(i18n.baseUrl), metaObject.link, identifierAttribute); | ||
addCanonicalLinks.call(this, vueDemi.unref(i18n.baseUrl), metaObject.link, identifierAttribute, addSeoAttributes); | ||
addCurrentOgLocale(currentLocale, currentLocaleIso, metaObject.meta, identifierAttribute); | ||
@@ -1023,3 +1065,3 @@ addAlternateOgLocales(locales, currentLocaleIso, metaObject.meta, identifierAttribute); | ||
} | ||
const VERSION = "0.3.0"; | ||
const VERSION = "0.4.0"; | ||
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; | ||
@@ -1032,2 +1074,5 @@ exports.DEFAULT_DETECTION_DIRECTION = DEFAULT_DETECTION_DIRECTION; | ||
exports.DEFAULT_TRAILING_SLASH = DEFAULT_TRAILING_SLASH; | ||
exports.DefaultLocalizeRoutesPrefixable = DefaultLocalizeRoutesPrefixable; | ||
exports.DefaultPrefixable = DefaultPrefixable; | ||
exports.DefaultSwitchLocalePathIntercepter = DefaultSwitchLocalePathIntercepter; | ||
exports.STRATEGIES = STRATEGIES; | ||
@@ -1034,0 +1079,0 @@ exports.VERSION = VERSION; |
@@ -15,3 +15,6 @@ import type { LocaleObject } from 'vue-i18n-routing' | ||
readonly localeCodes: string[] | ||
readonly __baseUrl: string | ||
/** | ||
* Base URL that is used in generating canonical links | ||
*/ | ||
baseUrl: string | ||
} | ||
@@ -18,0 +21,0 @@ |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.3.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"typecheck": "tsc -p . --noEmit", | ||
"switch:2": "vue-demi-switch 2 vue2 && vue-router-switch 3 vue-router3 && vue-i18n-switch 8 vue-i18n-legacy", | ||
"switch:3": "vue-demi-switch 3 && vue-router-switch 4 && vue-i18n-switch 9", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cover": "vitest --coverage", | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
}, | ||
"version": "0.4.0-5e3c7b4", | ||
"dependencies": { | ||
@@ -117,3 +106,14 @@ "@intlify/shared": "next", | ||
}, | ||
"sideEffects": false | ||
} | ||
"sideEffects": false, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"typecheck": "tsc -p . --noEmit", | ||
"switch:2": "vue-demi-switch 2 vue2 && vue-router-switch 3 vue-router3 && vue-i18n-switch 8 vue-i18n-legacy", | ||
"switch:3": "vue-demi-switch 3 && vue-router-switch 4 && vue-i18n-switch 9", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cover": "vitest --coverage", | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
148428
6.55%4015
5.46%