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

99
Views
Nested routes won't work using React Router 6

When I click Add card button (IconButton component) I should be able to navigate to the Add card page but it doesn't work.

This is my code:

App.js:

<Routes>
  <Route index element={<Home />} />
  <Route path="login" element={<Login />} />
  <Route path="signup" element={<Signup />} />
  <Route path="manage-cards" element={<ManageCards />}>
    <Route path="add-card" element={<h1>Hello world</h1>} />
  </Route>
  <Route path="manage-code" element={<ManageCode />} />
</Routes>

ManageCards.jsx:

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

import IconButton from "../../components/iconButton/IconButton";

import addCardIcon from "../../assets/img/Add card.png";

const ManageCards = () => {
  return (
    <div className="manage-cards">
      <div className="manage-cards__buttons">
        <Link to="add-card">
          <IconButton
            icon={addCardIcon}
            altText="Add card"
            iconText="Add card"
          />
        </Link>
      </div>
    </div>
  );
};

export default ManageCards;
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

An <Outlet> should be used in parent route elements to render their child route elements. This allows nested UI to show up when child routes are rendered. If the parent route matched exactly, it will render a child index route or nothing if there is no index route.

Did you add Outlet ?

about 4 years ago · Juan Pablo Isaza Report

0

Use it

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

import IconButton from "../../components/iconButton/IconButton";

import addCardIcon from "../../assets/img/Add card.png";

const ManageCards = () => {
  return (
    <div className="manage-cards">
      <div className="manage-cards__buttons">
        <Link to="add-card">
          <IconButton
            icon={addCardIcon}
            altText="Add card"
            iconText="Add card"
          />
        </Link>
      </div>

     <Outlet />
    </div>
  );
};

export default ManageCards;
about 4 years ago · Juan Pablo Isaza Report

0

I wanted to render the add-card in a different page, the problem with Outlet will cause it to render in the same page. So that's how I managed to fix the issue:

<Routes>
  <Route index element={<Home />} />
  <Route path="login" element={<Login />} />
  <Route path="signup" element={<Signup />} />
  <Route path="manage-cards">
    <Route index element={<ManageCards />} />
    <Route path="add-card" element={<h1>Hello world</h1>} />
  </Route>
  <Route path="manage-code" element={<ManageCode />} />
</Routes>

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!