#Redirects thrown by a route loader are caught by the parent of the route, not self/redirect target!

1 messages · Page 1 of 1 (latest)

storm spear
#

Hi everyone, I have some routes that look like this:

-routes
  -_panel
    -sales
      -route.tsx
    -route.tsx
  -login
    -route.tsx

The above gives me a route, /sales, that is rendered nested in the _panel/route.tsx Outlet. In the sales/route.tsx loader, I am checking user roles for view access, and throwing a redirect("/login", 401). I also have the v2_errorBoundary flag enabled in the remix config.

My issue is, when I throw a redirect in my sales route, three things happen:

  1. The redirect doesn't complete.
  2. The error boundary I've placed in _panel/route.tsx is rendered.
  3. The redirect completes properly if I omit the status code in the redirect and do throw redirect("/login")!

My intuition is that the error boundary at sales/route.tsx would be rendered since that file's loader threw the error! If not that, maybe the error boundary in my login/route.tsx file should render. Is this understanding wrong?

What I want to achieve (and what I believed Remix would do) is to render the layout at panel/route.tsx and render the error boundary in the Outlet! 🤔 Please correct me if I'm going about this incorrectly! 🙏

pliant cosmos
#

For 1 - a 401 isn't a redirect, so that's why it wouldn't actually redirect

#

As for throwing a non-redirect from the sales/route loader, it should end up in the sales/route error boundary if one is exported - so if that's not happening a reproduction would be helpful so we can dig into what's going on there