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

73
Views
React Link element v5 not taking me to the desired page

I'm having trouble with this simple react routing. The problem is that after I click on "Go to invoices" or "Go to eshop", the URL changes, but the page content remains the same. It only changes if I am at localhost:1234/eshop (or /dashboard) and reload the page.

import { BrowserRouter as Router, Route, Link } from "react-router-dom";    
export default function App() {
  return (
    <Router>
      <h1>Default layout</h1>
      <Link to="/invoices">Go to invoices</Link>
      <Link to="/eshop">Go to eshop</Link>

      <Route path="/invoices">
        <h2>Invoices page</h2>
      </Route>
      <Route path="/eshop">
        <h2>eshop page</h2>
      </Route>
    </Router>
  );
}

Any ideas how to fix this? edit sandbox here https://codesandbox.io/s/hungry-cloud-i2hui2?file=/src/App.js

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It's a clash between React Router and StrictMode.

One possible solution is to place the Router outside of StricMode, in the index.js file itself:

import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter as Router } from "react-router-dom";
import App from "./App";

const rootElement = document.getElementById("root");
const root = createRoot(rootElement);

root.render(
  <Router>
    <StrictMode>
      <App />
    </StrictMode>
  </Router>
);

See: here and here

about 4 years ago · Juan Pablo Isaza Report

0

You should wrap your Route components with a Switch component.

import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";    

export default function App() {
  return (
  <Router>
   <h1>Default layout</h1>
   <Link to="/invoices">Go to invoices</Link>
   <Link to="/eshop">Go to eshop</Link>
   <Switch>
    <Route path="/invoices">
      <h2>Invoices page</h2>
    </Route>
    <Route path="/eshop">
      <h2>eshop page</h2>
    </Route>
  </Switch>
 </Router>
 )
}

https://v5.reactrouter.com/web/guides/quick-start

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!