Regions is a view of the Research Gallery: the /regions index redirects there (every language); menu item off; detail pages kept
This commit is contained in:
parent
7114d0a6fd
commit
f3e4623216
3 changed files with 39 additions and 3 deletions
|
|
@ -6,6 +6,27 @@
|
|||
|
||||
import type { RegionSummary } from '~~/config/countries-meta'
|
||||
|
||||
// Regions is a view of the Research Gallery now, so /regions (in every language) REDIRECTS there with
|
||||
// ?tab=regions-dashboard and old links keep working. The region and country detail pages (/regions/<slug>)
|
||||
// stay. Set USE_LEGACY_REGIONS_PAGE to true (inside the middleware) to bring this index page back.
|
||||
definePageMeta({
|
||||
middleware: [(to) => {
|
||||
const USE_LEGACY_REGIONS_PAGE = false
|
||||
if (!USE_LEGACY_REGIONS_PAGE) {
|
||||
const base = String((useRuntimeConfig().public as { researchGalleryUrl?: string }).researchGalleryUrl || '')
|
||||
const lang = (useNuxtApp().$i18n as { locale: { value: string } })?.locale?.value
|
||||
try {
|
||||
const u = new URL(base)
|
||||
u.searchParams.set('tab', 'regions-dashboard')
|
||||
if (lang && lang !== 'en') u.searchParams.set('lang', lang)
|
||||
return navigateTo(u.toString(), { external: true, redirectCode: 301 })
|
||||
} catch {
|
||||
return navigateTo(to.path.replace(/\/regions\/?$/, '/research'), { redirectCode: 301 })
|
||||
}
|
||||
}
|
||||
}]
|
||||
})
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const localePath = useLocalePath()
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ export default defineNuxtModule({
|
|||
const prefixes = ['', ...ENABLED_LANGUAGE_CODES.filter(code => code !== 'en').map(code => `/${code}`)]
|
||||
const routes: string[] = []
|
||||
for (const prefix of prefixes) {
|
||||
routes.push(`${prefix}/regions`)
|
||||
// The /regions index is not prerendered when a route rule redirects it (LEGACY_REGIONS_PAGE in nuxt.config.ts).
|
||||
const indexRule = (nuxt.options.routeRules as Record<string, { redirect?: unknown }> | undefined)?.[`${prefix}/regions`]
|
||||
if (!indexRule?.redirect) routes.push(`${prefix}/regions`)
|
||||
for (const slug of slugs) routes.push(`${prefix}/regions/${slug}`)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,11 +44,24 @@ const marketingRouteRules = Object.fromEntries(
|
|||
// be a static glob); these rules just apply the marketing HTML cache policy
|
||||
// across all enabled locales. The former /countries URLs redirect permanently
|
||||
// to their /regions equivalents (same slugs) so old links keep working.
|
||||
// REGIONS IS A VIEW OF THE RESEARCH GALLERY: the /regions INDEX 301s to the gallery's Regions tab in every
|
||||
// language (the region/country detail pages stay). LEGACY_REGIONS_PAGE = true brings the index back: it
|
||||
// restores these rules and its prerender entry (modules/region-routes.ts). The page's own middleware covers
|
||||
// in-app navigation.
|
||||
const LEGACY_REGIONS_PAGE = false
|
||||
// The subdomain branch: the Regions view lives on the gallery's own subdomain; ?lang carries the locale.
|
||||
const REGIONS_GALLERY_URL = (process.env.NUXT_PUBLIC_RESEARCH_GALLERY_URL || 'https://research.nuxtbase.app').replace(/\/+$/, '')
|
||||
const regionsTarget = (prefix: string) =>
|
||||
`${REGIONS_GALLERY_URL}/?tab=regions-dashboard${prefix ? `&lang=${prefix.replace(/^\//, '')}` : ''}`
|
||||
const regionRouteRules = Object.fromEntries(
|
||||
MARKETING_LOCALE_PREFIXES.flatMap(prefix => [
|
||||
[`${prefix}/regions`, { headers: { 'cache-control': MARKETING_HTML_CACHE } }],
|
||||
LEGACY_REGIONS_PAGE
|
||||
? [`${prefix}/regions`, { headers: { 'cache-control': MARKETING_HTML_CACHE } }]
|
||||
: [`${prefix}/regions`, { redirect: { to: regionsTarget(prefix), statusCode: 301 } }],
|
||||
[`${prefix}/regions/**`, { headers: { 'cache-control': MARKETING_HTML_CACHE } }],
|
||||
[`${prefix}/countries`, { redirect: { to: `${prefix}/regions`, statusCode: 301 } }],
|
||||
LEGACY_REGIONS_PAGE
|
||||
? [`${prefix}/countries`, { redirect: { to: `${prefix}/regions`, statusCode: 301 } }]
|
||||
: [`${prefix}/countries`, { redirect: { to: regionsTarget(prefix), statusCode: 301 } }],
|
||||
[`${prefix}/countries/**`, { redirect: { to: `${prefix}/regions/**`, statusCode: 301 } }]
|
||||
])
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue