How do you implement a catch-all route for handling 404 errors in React Router

0 votes
Can you tell me How do you implement a catch-all route for handling 404 errors in React Router?
Apr 21 in Node-js by Ashutosh
• 28,250 points
74 views

1 answer to this question.

0 votes

To set up a catch-all route for managing 404 errors in React Router, include a route with path "*" at the end of your routes.

import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';

import Home from './Home';

import About from './About';

import NotFound from './NotFound'; // 404 component

function App() {

  return (

    <Router>

      <Routes>

        <Route path="/" element={<Home />} />

        <Route path="/about" element={<About />} />

        {/* Catch-all 404 route */}

        <Route path="*" element={<NotFound />} />

      </Routes>

    </Router>

  );

}

answered Apr 21 by anonymous

Related Questions In Node-js

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do you implement breadcrumbs in a React-Router app?

Breadcrumbs help users navigate by showing the ...READ MORE

answered Feb 24 in Node-js by Kavya
164 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP