Skip to content

Redirect from beforeLoad: uncaught error #1480

Closed

Description

@bazo

Describe the bug

when checking if user is authenticated and throwing a redirect from before load an unhandled error is thrown instead of redirect happenning

Your Example Website or App

https://stackblitz.com/edit/github-qtxl7r?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

run the app
open console
try to go to /posts

this error is thrown
router.ts:1607
Uncaught (in promise)
{to: '/login', search: {…}, isRedirect: true, statusCode: 301, headers: {…}, …}

Expected behavior

i am redirected to login page

Screenshots or Videos

No response

Platform

  • OS: mac
  • Browser: edge
  • Version: 122.0.2365.80 (Official build) (arm64)

Additional context

No response

Activity

  1. tannerlinsley commented on Apr 17, 2024

    @tannerlinsley
    Member

    Should be fixed in latest!

  2. gregflynn commented on Apr 18, 2024

    @gregflynn

    Still seeing this in 1.28.7

  3. gregflynn commented on Apr 18, 2024

    @gregflynn

    as seen in other issues, downgrading to 1.28.1 is a solid workaround

  4. AndrejNemec commented on Apr 18, 2024

    @AndrejNemec

    +1

    Another scenario involves manually entering a URL that belongs to an authenticated layout directly into the address bar. If I navigate to that page manually, not using a Link or navigate function, the same error occurs.

  5. bazo commented on Apr 19, 2024

    @bazo
    Author

    yeah still happens, even on 1.28.9

  6. 6jonathanaloi6 commented on Apr 19, 2024

    @6jonathanaloi6

    Still happens in 1.28.9

  7. nick-cheatwood7 commented on Apr 19, 2024

    @nick-cheatwood7

    as seen in other issues, downgrading to 1.28.1 is a solid workaround

    Can confirm, downgrading from 1.28.7 to 1.28.1 fixes the issue temporarily.

  8. added
    bug
    on Apr 20, 2024
  9. planktonrobo commented on Apr 20, 2024

    @planktonrobo

    Seeing this is broken in latest as well

  10. sher commented on Apr 21, 2024

    @sher
  11. vitoorgomes commented on Apr 21, 2024

    @vitoorgomes

    using the official example, even on latest version 1.29.2 or 1.28.1, although it works just fine when using the <Link> component to navigate, it keeps throwing the Uncaught error when manually navigating to /dashboard url

  12. junglast commented on Apr 22, 2024

    @junglast

    As mentioned above, this occurs to me when I initially hard-load the route that includes redirect in the browser address bar. It works well when navigating to that page on client side.

  13. artsiomshaitar commented on Apr 22, 2024

    @artsiomshaitar

    Still happens in 1.29.2

  14. angelsantosa commented on Apr 22, 2024

    @angelsantosa

    Also happens using loader in route.
    image

  15. andelkocvjetkovic commented on Apr 23, 2024

    @andelkocvjetkovic

    Experiencing the same issue.

  16. felix-bohlin commented on Apr 23, 2024

    @felix-bohlin
    Contributor

    Same here, but it only happens in my prod build.
    I downgraded to 1.28.1 and it worked again.

    "@tanstack/react-router": "^1.29.2",
    "@tanstack/router-vite-plugin": "^1.30.0",
    "vite": "^5.2.10",
  17. hugocostadev commented on Apr 25, 2024

    @hugocostadev
    Contributor

    Still happening with the latest version.

    Error:
    image

    Code:

    "@tanstack/react-router": "^1.30.1",
    "@tanstack/router-devtools": "^1.30.1",
    "@tanstack/router-vite-plugin": "^1.30.0",
    import { createFileRoute, redirect } from "@tanstack/react-router";
    
    export const Route = createFileRoute("/")({
      beforeLoad: () => {
        throw redirect({ to: "/home" });
      },
    });
  18. angelsantosa commented on Apr 25, 2024

    @angelsantosa

    Hey, I just tested the new change, and while redirect does work, now it does not show Outlet content.
    You can see the behavior here: https://stackblitz.com/edit/vitejs-vite-pcqzrt?file=src%2Fmain.tsx

  19. added a commit that references this issue on Apr 26, 2024
    791e08d
  20. vafanassieff commented on Apr 26, 2024

    @vafanassieff
    Contributor

    There is no more error in the console, but the redirect does not load the current page and leave me with an empty screen.

  21. hugocostadev commented on Apr 26, 2024

    @hugocostadev
    Contributor

    There is no more error in the console, but the redirect does not load the current page and leave me with an empty screen.

    Same here

  22. miroslavmih commented on Apr 30, 2024

    @miroslavmih

    Tested in

    @tanstack/react-router": "^1.31.3

    and it seems that redirect doesn't work, i.e.

    throw redirect({ to: '/' });

    will redirect to current page and not to: '/'

  23. mykhailoalekseiev commented on May 2, 2024

    @mykhailoalekseiev

    Wrapping the <RouterProvider router={router} /> in Suspense component helped me to resolve this issue.

  24. dedene commented on May 6, 2024

    @dedene

    Wrapping the <RouterProvider router={router} /> in Suspense component helped me to resolve this issue.

    This does not seem to help for our case. throw redirect({ to: '/login', search: { redirect: location.href }}); is changing the url, but showing a blank screen, suggesting indeed the Outlet is not rendering?

  25. dedene commented on May 6, 2024

    @dedene

    Ah, version 1.31.20 seems to have a fix! 🙌 Probably 51eb39b fixed it, it is working after updating. Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions