How to let React Router v6 respond with 404 status code

Viewed 871

In React Router v5, we could provide a 404 response code in this way :

<Route path="*" component={NoMatch} status={404}/>

But how can we do it with React Router v6?

1 Answers

The react-router-dom v5 Route components don't have a status prop, and neither do the v6 Route components. If this is simply passing the status prop through to the routed component then in RRDv6 you can pass it directly to the NoMatch component as a prop.

<Route
  path="*"
  element={<NoMatch status={404} />}
/>
Related