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

192
Visualizações
How to link different react pages?

I am new to react,

I want to connect the button on the main page with a separate react page. Here I want to connect the contact link href directing to the contact react page.

import React from 'react';

(function Nav (){
    return(
        <div id="navid">
            <nav className="navbar fixed-top navbar-expand-lg">
            
                <a className="navbar-brand" href="home">Manav</a>
                <div className="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul className="navbar-nav ml-auto">
                        <li className="nav-item">
                            <a className="nav-link" href="./Contact">Colab</a>
                        </li>
                        <li className="nav-item">
                            <a className="nav-link" href="x">Blogs</a>
                        </li>
                    </ul>
                </div>

            </nav>
        </div>
        
    );
    
}

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

0

Since React apps are usually SPA's (Single Page Application) that means that usually there is just one html page and react will handle the content switching on the page. So using <a> tags will not work since it expects a separate HTML page to exist which does not exist.

The correct way is to use a routing library like react-router and use its Link component to handle the routing or switching the pages.

about 4 years ago · Juan Pablo Isaza Relatório

0

You have to use react-router-dom npm package to perform routing operations in react.

about 4 years ago · Juan Pablo Isaza Relatório

0

  1. First you have to install npm install react-router react-router-dom
  2. Now import import { Switch, Route, BrowserRouter } from "react-router-dom" in your App.js file.
  3. Now use <BrowserRouter> <Switch> <Route> tags as shown below:

import Blogs from "./Components/Blogs";
import Colab from "./Components/Colab";
import Nav from "./Pages/Nav";
import { Switch, Route, BrowserRouter } from "react-router-dom";

const App = () => {
  return (
    <div className="App">
      <BrowserRouter>
        <Nav />
        <Switch>
          <Route path="/BLog">
            <Blog />
          </Route>
          <Route path="/Colab">
            <Colab />
          </Route>
        </Switch>
      </BrowserRouter>
    </div>
  );
};

export default App;

  1. after setting up Routes of components in App.js go to your Nav.js
  2. import {Link} from "react-router-dom" in Nav.js and set the Links to the path as shown below:

import React from "react";
import { Link } from "react-router-dom";

const Nav = () => {
  return (
    <div>
      <Link to="Blog" style={linkStyle}>
        Blog
      </Link>
      <Link to="Colab" style={linkStyle}>
        Colab
      </Link>
    </div>
  );
};

export default Nav;

Yo dont need to use <a className="nav-link" href="x">Blogs</a> instead we use Link and Route. You can get more information from the documentation of react-Route-dom

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