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
3cd93da61d
commit
97449c5fc3
4 changed files with 28 additions and 4 deletions
|
|
@ -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/<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) {
|
||||
// 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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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' }
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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,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 } }]
|
||||
])
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue