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

148
Views
How to show not found on base url

This is the code:

App

import { Route, BrowserRouter as Router, Routes } from "react-router-dom";
import ClassroomDashboard from "./ClassroomDashboard";
import Students from "./Students";
import NotFound from "./NotFound";
import Base from "./Base";
import "./styles.css";

export default function App() {
  return (
    <Router>
      <Routes>
        <Route path="/" element={<Base />}>
          <Route path="dashboard" element={<ClassroomDashboard />} />
          <Route path="students" element={<Students />} />
          <Route index element={<NotFound />} />
        </Route>
      </Routes>
    </Router>
  );
}

Base

import { Outlet } from "react-router-dom";

function Base() {
  return <Outlet />;
}

export default Base;

NotFound

function NotFound() {
  return "NotFound";
}

export default NotFound;

https://codesandbox.io/s/summer-sound-giti8c?file=/src/App.js

I want that when someone goes to the base url say https://giti8c.csb.app/ then NotFound component should be rendered.

Currently, only Base component renders on going to the base url.

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

0

I want that when someone goes to the base url say "https://giti8c.csb.app/" then NotFound component should be rendered.

Make an index route that also renders the NotFound component, to be matched and rendered only when the path exactly matches the parent route rendering the Outlet component.

See Index Routes

Example:

<Router>
  <Routes>
    <Route path="/" element={<Base />}>
      <Route index element={<NotFound />} />
      <Route path="dashboard" element={<ClassroomDashboard />} />
      <Route path="students" element={<Students />} />
    </Route>
    <Route path="*" element={<NotFound />} />
  </Routes>
</Router>
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!