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

82
Visualizações
how to create new react routes in a component according to the props?

I am trying to create a new react routes according to the props of components. App.js routes the landing page to the Home component.

import "./App.css";
import Navbar from "./components/Navbar";
import Home from "./components/Home";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";

function App() {
    return (
        <div>
            <Navbar />
            <Router>
                <Routes>
                    <Route path="/" element={<Home />} />
                </Routes>
            </Router>
        </div>
    );
}

export default App;

I have service card file where I want to create new routes according to props. Like for example

route = lorem -> /services/lorem
route = ipsum -> /services/ipsum

Servicecard looks like this

import React from "react";
import "../css/servicecard.css";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Home from "./Home";

const ServiceCard = ({ text, subClass, image, route }) => {
    return (
        <>
            <div className={`card-container ${subClass}`} data-aos="fade-up">
                <span className="card-title">{text}</span>

                <img src={image} alt="service-icon" />
            </div>
        </>
    );
};

export default ServiceCard;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i think you are talking about route params, here is an example:

export default function ParamsExample() {
  return (
    <Router>
      <div>
        <h2>Accounts</h2>

        <ul>
          <li>
            <Link to="/netflix">Netflix</Link>
          </li>
          <li>
            <Link to="/zillow-group">Zillow Group</Link>
          </li>
          <li>
            <Link to="/yahoo">Yahoo</Link>
          </li>
          <li>
            <Link to="/modus-create">Modus Create</Link>
          </li>
        </ul>

        <Switch>
          <Route path="/:param" children={<Child />} />
        </Switch>
      </div>
    </Router>
  );
}

and in the component child:

function Child() {

  let { param } = useParams();

  return (
    <div>
      <h3>ID: {param}</h3>
    </div>
  );
}
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