Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Siguiente.JS getInitialProps(ctx) ctx no está definido

este es mi codigo

 import NavLayout from "../../components/Navigation/Navigation"; export default function WorldOfWarcraft({ game }) { return (<NavLayout> {game.link} </NavLayout>) } WorldOfWarcraft.getInitialProps = async (ctx) => { const response = await fetch(`http://localhost:6969/favGames/${ctx.query.id}`); const game = await response.json(); return { game }; }

Tengo el mismo código en otra 'página' y funciona bien. Este es absolutamente el mismo código con diferentes nombres y no funciona. Cuando intento iniciar sesión en ctx , devuelve indefinido. Además, esto es 'index.js'

 import Link from "next/link"; import NavLayout from "../../components/Navigation/Navigation"; export default function FavGames({ games }) { console.log(games); return (<NavLayout title={'Fav Games Page'}> <h1>Favorite Games</h1> <ul> {games.map(game => ( <li key={game.id}> <Link href={`/fav-games/[games]`} as={`/fav-games/${game.id}`}> <a> {game.title} </a> </Link> </li> ))} </ul> </NavLayout>); } FavGames.getInitialProps = async () => { const response = await fetch('http://localhost:6969/favGames'); const games = await response.json(); return { games }; }

Entonces, enlazo de index.js a [games].js dinámicamente. No entiendo por qué ctx devolvió undefined :(

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

lo he resuelto Esto es Loco. Estuve atascado durante 2 días y la razón fue que en este código:

 <Link href={`/fav-games/[games]`} as={`/fav-games/${game.id}`}>

[games] es lo que necesito. Así que aquí en lugar de esto

 const response = await fetch(`http://localhost:6969/favGames/${ctx.query.***id***}`);

debería ser esto:

 const response = await fetch(`http://localhost:6969/favGames/${ctx.query.***games***}`);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!