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

324
Visualizações
Why can't rendering HTML page in React application?

I have 3 components in my React application that I use for Nav Bar. In each component, there is a div element with id = 'root'

Index.html

<div id="root"></div>

This is how it looks my App.js -

App.js

import logo from './logo.svg';
import './App.css';

import {Home} from './Home';
import {Department} from './Department';
import {Employee} from './Employee';
import {Navigation} from './Navigation';
import {BrowserRouter, Route, Routes} from 'react-router-dom';

function App() {
  return (
    <BrowserRouter>
    <div className="container">
      <h3 className="m-3 d-flex justify-content-center">
          React JS Tutorial
      </h3>

    <Navigation/>
    <Routes>
      <Route path='/' component={Home} exact/>
      <Route path='/department' component={Department}/>
      <Route path='/employee' component={Employee}/>
    </Routes>

    </div>
    </BrowserRouter>
  );
}

Example of Department Component:

Department.js

import React, {Component} from 'react';

export class Department extends Component{

    render(){
        return(
            <div className="mt-5 d-flex justify-content-left">
                This is Department page
            </div>
        )
    }
}

This is my index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { Home } from './Home';


//ReactDOM.render(React.createElement(App, null), document.getElementById('root'));


const root = ReactDOM.createRoot(
    document.getElementById('root')
  );
  
  const element = <h1>Hello, world</h1>;
  root.render(React.createElement(App, null), document.getElementsByClassName('root'));

I tried to use ReactDOM instead but without any success, this is how it looks

enter image description here

Update Solved
The problem was that I route by component instead element
Wrong <Route path='/department' component={Department}/>
Correct <Route path='/department' element={<Department/>}/>

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

Solved
The problem was that I route by component instead element
Wrong <Route path='/department' component={Department}/>
Correct <Route path='/department' element={<Department/>}/>

about 4 years ago · Santiago Gelvez Relatório

0

You are using getElementsByClassName, but your div: <div id="root"></div> does not have a property class="root"

use getElementById("root") instead.

about 4 years ago · Santiago Gelvez 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