this post was submitted on 30 Jul 2023
1 points (100.0% liked)

React

857 readers
1 users here now

A community for discussing anything related to the React UI framework and it's ecosystem.

https://react.dev/

Wormhole

[email protected]

Icon base by Skoll under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

Using react router and have a route definition:

  {
       path: '/',
       element: <Root pageTitle={pageTitle} />,
       errorElement: <ErrorPage setPageTitle={updatePageTitle} />,
       children: [
          ...
          {
             path: '*',
             element: <ErrorPage setPageTitle={updatePageTitle} />,
             loader: async () => {
                throw new Response('Not Found', { status: 404 });
             },
          },
       ],
    },

This shows me 404 page how I want but without the rest of the root element but also the http status is reported as 200. How do I properly throw it as a 404 and show it inside root element?

top 2 comments
sorted by: hot top controversial new old
[โ€“] [email protected] 1 points 1 year ago (1 children)

React-router is client-side routing. You're not making an HTTP request, so there's no status code to set. If you're doing server-side rendering that's a different story but as it stands you can't accomplish what you're wanting and frankly I'm not sure why you would want to.

[โ€“] [email protected] 1 points 1 year ago

Oh I see my mistake, thank you for explaining it!