Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!