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

138
Views
Link not giving any output with 'react-router-dom'

I'm trying to add a NavBar to the app.js file I have in react. When I load the page the Route files are loading but the Link files set in NavBar aren't appearing.

This is the NavBar page

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

const NavBar = () => ( 
        <nav>
            <ul>
                <li>
                    <Link to="/">Home</Link>
                </li>
                <li>
                    <Link to="/about">About</Link>
                </li>
                <li>
                    <Link to="/article">Article</Link>
                </li>
                <li>
                    <Link to="/article-list">Article List</Link>
                </li>
            </ul>
        </nav>
)

export default NavBar;

Then below is the app.js file

import Homepage from './Pages/Homepage';
import AboutPage from './Pages/AboutPage';
import ArticlesList from './Pages/ArticlesList';
import ArticlePage from './Pages/ArticlePage';
import NavBar from './NavBar';
import {Routes, Route} from 'react-router-dom';

import './App.css';

function App() {
  return (
    <Routes>
      <div className="App">
        <NavBar />
        <div id="page-body">
          <Route path="/" element={<Homepage />} />
          <Route path="/about" element={<AboutPage />}/>
          <Route path="/article-list" element={<ArticlesList />} />
          <Route path="/article" element={<ArticlePage />} />
      </div>
    </div>
    </Routes>
  );
}

export default App;

I am keeping NavBar out of the pages folder I'm stumped as to what it could be

Just incase the react-router-dom version I have in my package.json file is:

    "react-router-dom": "^6.0.0-beta.6",

index.js file:

import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter as Router} from "react-router-dom";
import './index.css';
import App from './App';


ReactDOM.render(
  <Router>
    <App />
  </Router>,
  document.getElementById('root')
);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think your navbar should be outside of your Routes tag in app.js, and then inside your navbar file, wrap everything around a tag.

App.js should look like this:

import Homepage from './Pages/Homepage';
import AboutPage from './Pages/AboutPage';
import ArticlesList from './Pages/ArticlesList';
import ArticlePage from './Pages/ArticlePage';
import NavBar from './NavBar';
import {Routes, Route} from 'react-router-dom';

import './App.css';

function App() {
  return (
   <div>
    <NavBar />
    <Routes>
      <div className="App">
        
        <div id="page-body">
          <Route path="/" element={<Homepage />} />
          <Route path="/about" element={<AboutPage />}/>
          <Route path="/article-list" element={<ArticlesList />} />
          <Route path="/article" element={<ArticlePage />} />
        </div>
      </div>
    </Routes>
    </div>
  );
}

export default App;

Additionally, your nav component should look something like this:

   import React from 'react';
import { Link, Routes } from 'react-router-dom';

const NavBar = () => ( 
        <nav>
          <Routes>
            <ul>
                <li>
                    <Link to="/">Home</Link>
                </li>
                <li>
                    <Link to="/about">About</Link>
                </li>
                <li>
                    <Link to="/article">Article</Link>
                </li>
                <li>
                    <Link to="/article-list">Article List</Link>
                </li>
            </ul>
          </Routes>
        </nav>
)

export default NavBar;

You might also be running into a problem with the fact that you are wrapping around your App component with a but i am not 100% sure on this one.

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!