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

147
Visualizações
Using App component as a home page in react (path "/")

this is my first question here and I apologize upfront if it already been answered. I'm studying react and I started a project as well, and my question is: how can I make my App component a home page? Or do I have to create a component to do so? I´m using react-router-dom for navigation, like the code below, and keep getting the message "No routes matched location "/"". How can I set a route to it? I would like to use the App component instead of using a page component named home. If I did something wrong about the post, again, I'm sorry. Thanks in advance.

import React from 'react'
import {BrowserRouter as Router, Routes, Route, Link} from 'react-router-dom'

import Blog from './pages/Blog'
import About from './pages/About'
import Faq from './pages/Faq'
import Market from './pages/Market'

import GlobalStyle from './styles/global'

function App() {

  return (
    <Router>

      <GlobalStyle/>

      <header>
        <nav>
          <Link to="/products">Nosso produtos</Link>
          <Link to="/blog">Diário do Café</Link>
          <Link to="/faq">Cafaq - perguntas frequentes</Link>
          <Link to="/about">Sobre nós</Link>
        </nav>
      </header>        

      <Routes>
        <Route path="/products" element={<Market />} />
        <Route path="/blog" element={<Blog />} />
        <Route path="/faq" element={<Faq />} />
        <Route path="/about" element={<About />} />
      </Routes>
      
      <footer> Footer </footer>
    </Router>
  )
}

export default App
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The route element with path ="/" will be your home page

about 4 years ago · Juan Pablo Isaza Relatório

0

Try with this;

<Route path='/' exact element={<Home/>} />

about 4 years ago · Juan Pablo Isaza Relatório

0

The App component is already your default component. Any path will render the App component as long as you have wrapped the App component with the BrowserRouter component

// In index.js
import App from "./App";
import { BrowserRouter } from "react-router-dom";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <BrowserRouter>
     <App />
  </BrowserRouter>
);

so I assume your point is to keep the navbar visible regardless of the current path and that is already done because anything placed in the App component will be rendered, and the paths content will be changed based on the elements specified in the Routes.

In case, you want to create a separate Home component, then you will create a Route with a path '/' and the Home Component element.

Make sure that you understand how routing works to avoid any bugs in the future

Hope you found it helpful.

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