Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
routing to a new page from navbar with react routing

I'm trying to make a 2nd page for my website and I'm having hard time understanding how react routing works .

Here's the code:

import { FaGithub, FaUserAstronaut, FaLinkedin } from 'react-icons/fa';
import MarsSvg from './MarsSvg';
import MarsPage from '../pages/MarsPage'; 
import { Routes, Route } from "react-router-dom"



function NavBar () {
  return (
    <nav className=''>
      <div className="flex justify-around items-center text-5xl">
        <Routes>
          <Route path="/mars" element={<MarsPage />} />
        </Routes>
 
        <MarsSvg/>
        <ul className='flex  hover:scale-125 hover:bg-white duration-500 rounded-full'>
          <a href='https://github.com/DevSnippy'>
            <FaGithub/>
          </a>
        </ul>

        <ul className='flex  hover:scale-125 hover:bg-white duration-500 rounded-full'>
          <FaUserAstronaut/>
        </ul>

        <ul className='flex  hover:scale-125 hover:bg-white duration-500 rounded-full'>
          <FaLinkedin/>
        </ul>
      </div>
    </nav>
  )
}

export default NavBar

It does render a component but I want 2 things to happen:

  • 1st for the user to click an icon to activate the route
  • 2nd for it to a new blank page
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I add BrowserRouter over the component to get the routes to work (wont work without). Then I used Link from react-router-dom to go to a new page upon clicking your svg icon.

(see: https://reactrouter.com/docs/en/v6/getting-started/overview)

import React from "react";
import { FaGithub, FaUserAstronaut, FaLinkedin } from "react-icons/fa";
import MarsSvg from './MarsSvg';
import MarsPage from '../pages/MarsPage'; 
import { Routes, Route, BrowserRouter, Link } from "react-router-dom";

function NavBar() {
  return (
    <BrowserRouter>
      <nav className="">
        <div className="flex justify-around items-center text-5xl">
          <Routes>
            <Route path="/mars" element={<MarsPage />} />
          </Routes>
          <Link to="/mars">
          <MarsSvg/>
          </Link>
          <ul className="flex  hover:scale-125 hover:bg-white duration-500 rounded-full">
            <a href="https://github.com/DevSnippy">
              <FaGithub />
            </a>
          </ul>
          <ul className="flex  hover:scale-125 hover:bg-white duration-500 rounded-full">
            <FaUserAstronaut />
          </ul>
          <ul className="flex  hover:scale-125 hover:bg-white duration-500 rounded-full">
            <FaLinkedin />
          </ul>
        </div>
      </nav>
    </BrowserRouter>
  );
}

export default NavBar;

Is this what you meant?

Edit: Switched incorrect link from v5 to v6

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda