Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support localePath with path input and customized routes #1088

Merged
merged 16 commits into from
Mar 7, 2021
33 changes: 23 additions & 10 deletions src/templates/plugin.routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,29 @@ function localeRoute (route, locale) {
const isDefaultLocale = locale === defaultLocale
// if route has a path defined but no name, resolve full route using the path
const isPrefixed =
// don't prefix default locale
!(isDefaultLocale && [STRATEGIES.PREFIX_EXCEPT_DEFAULT, STRATEGIES.PREFIX_AND_DEFAULT].includes(strategy)) &&
// no prefix for any language
!(strategy === STRATEGIES.NO_PREFIX) &&
// no prefix for different domains
!i18n.differentDomains

let path = (isPrefixed ? `/${locale}${route.path}` : route.path)
path = path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/'
localizedRoute.path = path
// don't prefix default locale
!(isDefaultLocale && [STRATEGIES.PREFIX_EXCEPT_DEFAULT, STRATEGIES.PREFIX_AND_DEFAULT].includes(strategy)) &&
// no prefix for any language
!(strategy === STRATEGIES.NO_PREFIX) &&
// no prefix for different domains
!i18n.differentDomains
rchl marked this conversation as resolved.
Show resolved Hide resolved
const thisRoute = this.router.resolve(route.path).route
const routeName = this.getRouteBaseName(thisRoute)

if (isPrefixed && !routeName) {
let path = `/${locale}${route.path}`
path = path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/'
localizedRoute.path = path
} else {
localizedRoute.path = route.path.replace(/\/+$/, '') + (trailingSlash ? '/' : '') || '/'
rchl marked this conversation as resolved.
Show resolved Hide resolved
if (routeName) {
localizedRoute.name = getLocaleRouteName(routeName, locale)
localizedRoute.params = thisRoute.params
localizedRoute.query = thisRoute.query
localizedRoute.hash = thisRoute.hash
return this.router.resolve(localizedRoute).route
rchl marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
if (!route.name && !route.path) {
localizedRoute.name = this.getRouteBaseName()
Expand Down