diff --git a/app/pages/regions/index.vue b/app/pages/regions/index.vue index 0dcf7ef4..2556a0f4 100644 --- a/app/pages/regions/index.vue +++ b/app/pages/regions/index.vue @@ -6,6 +6,19 @@ 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/) +// 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) { + // The locale is already in the path (/ar/regions -> /ar/research). + return navigateTo({ path: to.path.replace(/\/regions\/?$/, '/research'), query: { tab: 'regions-dashboard' } }, { redirectCode: 301 }) + } + }] +}) + const { t, locale } = useI18n() const localePath = useLocalePath() diff --git a/app/utils/nav.ts b/app/utils/nav.ts index 6ce27c96..44014b33 100644 --- a/app/utils/nav.ts +++ b/app/utils/nav.ts @@ -31,6 +31,6 @@ export const SECONDARY_NAV: NavItem[] = [ { key: 'Pray', to: '/pray' }, { key: 'Adopt', to: '/adopt' }, { key: 'Resources', to: '/resources' }, - { key: 'Regions', to: '/regions' }, + // Off: Regions is a view of the Research Gallery (/research?tab=regions-dashboard); /regions redirects there. { key: 'Give', href: 'https://giving.ag.org/donate/600001-6C2327?utm_source=direct_link' } ] diff --git a/modules/region-routes.ts b/modules/region-routes.ts index d24b799f..0f08df96 100644 --- a/modules/region-routes.ts +++ b/modules/region-routes.ts @@ -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 | undefined)?.[`${prefix}/regions`] + if (!indexRule?.redirect) routes.push(`${prefix}/regions`) for (const slug of slugs) routes.push(`${prefix}/regions/${slug}`) } diff --git a/nuxt.config.ts b/nuxt.config.ts index 83784361..577b4897 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -44,11 +44,20 @@ 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 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: `${prefix}/research?tab=regions-dashboard`, 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: `${prefix}/research?tab=regions-dashboard`, statusCode: 301 } }], [`${prefix}/countries/**`, { redirect: { to: `${prefix}/regions/**`, statusCode: 301 } }] ]) )