Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
React router changes url but not re-render

React Router change the URL but the component is not rendered I have already looked for answer but none of those example is worked Current React Router & React Router DOM version is 6. My MainComponent:

import React, { Component } from 'react';
import Header from './HeaderComponent';
import Footer from './FooterComponent';
import { Routes, Route, Redirect } from 'react-router-dom';
import Stafflist from './StaffComponent';
import {STAFFS} from '../shared/staffs';
import StaffDetail from './StaffDetailComponent';

class Main extends Component{
    constructor(props){
        super(props);
        this.state ={
            staffs : STAFFS
        };
    }
  
    render(){
        const StaffWithId = ({match}) =>{
            return(
                <StaffDetail staff={this.state.staffs.filter((staff) => staff.id === parseInt(match.params.staffId,10))}/>
            )
        }
        return(
            <div>
            <Header/>
                <Routes>
                    <Route exact path='/staff' element={<Stafflist staffs={this.state.staffs} />}/>
                    <Route path='/staff/:staffId' element={StaffWithId}/>
                </Routes>
            <Footer/>
      </div>
        );
    }
}

export default Main;

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your problem seems to be this line:
<Route path='/staff/:staffId' element={StaffWithId}/>

StaffWithId is a functional component and shoul be called with brackets < />.
like this: <Route path='/staff/:staffId' element={<StaffWithId/>}/>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda