Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
Having troubles with react-router-dom

I'm following this YouTube tutorial from JavaBrains https://www.youtube.com/watch?v=4iM7eEl3Rag&list=PLqq-6Pq4lTTa8V613TZhGq4o8hSgkMGQ0&index=9&t=292s

Everything goes smooth and well until he implements the BrowserRouter. The thing is that I copy exactly what he's doing but unfortunately I get a blank page, not matter what I change it's still blank. Any ideas how to solve it? I have asked also in the channel but with no answer. Thanks! The url will be: localhost:3000/teams/xxx

This is the piece of code of App.js

import './App.css';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { TeamPage } from './pages/TeamPage';

function App() {
  return (
    <div className="App">
      <Router>
        <Route path="/teams/:teamName">
          <TeamPage />
        </Route>
      </Router>
    </div>
  ); 
}

export default App;

and this is the TeamPage.js

import { React, useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { MatchDetailCard } from "../components/MatchDetailCard";
import { MatchSmallCard } from "../components/MatchSmallCard";

export const TeamPage = () => {

  const [team, setTeam] = useState({ matches: [] });
  const { teamName } = useParams();

  useEffect(
    () => {
      const fetchMatches = async () => {
        const response = await fetch(`http://localhost:8080/api/team/${teamName}`);
        const data = await response.json();
        setTeam(data);
      };
      fetchMatches();
    }, [teamName] //This empty array as a second argument tells: Call useEffect only when something inside change
  );

  if(!team || !team.teamName) {
    return <h1>Team Not Found</h1>
  }

  return (
    <div className="TeamPage">
      <h1>{team.teamName}</h1>

      <MatchDetailCard teamName={team.teamName} match={team.matches[0]} />
      {team.matches.slice(1).map((match) => 
        <MatchSmallCard teamName={team.teamName} match={match} />
      )}
    </div>
  );
};

export default TeamPage;

Hope you can help meee!!!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In react-router-dom@6 the API changed quite a bit. Route components must be rendered by a Routes component (it's like the v5 Switch) and the routed components are rendered via an element prop that takes a ReactElement, a.k.a. JSX.

Example:

import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { TeamPage } from './pages/TeamPage';

function App() {
  return (
    <div className="App">
      <Router>
        <Routes>
          <Route path="/teams/:teamName" element={<TeamPage />} />
        </Routes>
      </Router>
    </div>
  ); 
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda