web-next: ruta del reino dinámica /<slug>-realm (según realmlist)
La página del reino pasa de /novawow-realm (fija) a una ruta dinámica app/[locale]/[realm] cuyo slug es <nombre-del-reino>-realm, con el nombre tomado de acore_auth.realmlist (LIMIT 1). Ej.: realm «Trinity» → /trinity-realm. realmSlug() normaliza el nombre (minúsculas, sin espacios). Si el slug no coincide con el reino actual → notFound(). Convive con el catch-all [...rest] y las rutas estáticas mantienen prioridad (verificado: /login, /account OK; /foo y /novawow-realm → 404). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+26
-8
@@ -1,25 +1,43 @@
|
||||
import type { Metadata } from 'next'
|
||||
import { setRequestLocale } from 'next-intl/server'
|
||||
import { getRealmName } from '@/lib/realm'
|
||||
import { notFound } from 'next/navigation'
|
||||
import { getRealmName, realmSlug } from '@/lib/realm'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const realm = await getRealmName()
|
||||
return { title: `Reino - ${realm}` }
|
||||
// Ruta dinámica del reino: /<slug>-realm, donde <slug> viene del nombre del
|
||||
// reino en acore_auth.realmlist (p. ej. «Trinity» → /trinity-realm).
|
||||
async function resolveRealm(param: string): Promise<string | null> {
|
||||
const name = await getRealmName()
|
||||
return param === `${realmSlug(name)}-realm` ? name : null
|
||||
}
|
||||
|
||||
export default async function NovawowRealmPage({ params }: { params: Promise<{ locale: string }> }) {
|
||||
const { locale } = await params
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ realm: string }>
|
||||
}): Promise<Metadata> {
|
||||
const { realm } = await params
|
||||
const name = await resolveRealm(realm)
|
||||
return name ? { title: `Reino - ${name}` } : {}
|
||||
}
|
||||
|
||||
export default async function RealmPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ locale: string; realm: string }>
|
||||
}) {
|
||||
const { locale, realm } = await params
|
||||
setRequestLocale(locale)
|
||||
const realm = await getRealmName()
|
||||
const name = await resolveRealm(realm)
|
||||
if (!name) notFound()
|
||||
|
||||
return (
|
||||
<div className="main-page">
|
||||
<div className="middle-content">
|
||||
<div className="body-content">
|
||||
<div className="title-content">
|
||||
<h1>Reino - <span className="blue-info">{realm.toUpperCase()}</span></h1>
|
||||
<h1>Reino - <span className="blue-info">{name.toUpperCase()}</span></h1>
|
||||
</div>
|
||||
<div className="box-content centered">
|
||||
<div className="realm-information realm-information-half">
|
||||
@@ -12,3 +12,8 @@ export async function getRealmName(): Promise<string> {
|
||||
return 'NovaWoW'
|
||||
}
|
||||
}
|
||||
|
||||
/** Slug del reino para la URL (p. ej. «Nova WoW» → «novawow», «Trinity» → «trinity»). */
|
||||
export function realmSlug(name: string): string {
|
||||
return name.toLowerCase().replace(/[^a-z0-9]/g, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user