Skip to content

when trailingSlash: always loaders do not run if the trailing-slash is not present #1774

Closed

Description

@SeanCassiere

Describe the bug

From @TkDodo

found a small issue with route loaders and trailingSlash: always:

the loaders don't run if I navigate to a route without a trailing slash, like /about. This can happen if the user types in the url manually. What happens is:

  • the router appends a slash /about/
  • it renders the right component
  • but the loader of that component never runs.

reproduction: https://stackblitz.com/edit/tanstack-router-lhw7fj?file=src%2Fmain.tsx,src%2Froutes%2F__root.tsx,src%2Froutes%2Fabout.tsx&preset=node

if you navigate with the link to About, it will work, but if you open the sandbox preview in a new tab and go to /about, it doesn't work (I hope this link works): https://tanstackrouterlhw7fj-yhec--3001--9e2d28a3.local-credentialless.webcontainer.io/about (mising trailing slash on purpose)

it works fine with trailingSlash: 'preserve'

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-lhw7fj?file=src/main.tsx,src/routes/__root.tsx,src/routes/about.tsx&preset=node

Steps to Reproduce the Bug or Issue

❗ Navigating via Links works correctly, so you need to directly visit the URL.

  • To directly to /about without the ending /.
  • Observe loaders not running

Expected behavior

Loaders should run 👍🏼

Screenshots or Videos

No response

Platform

  • TSR Version: 1.38.1

Additional context

No response

Activity

  1. added
    bug
    on Jun 18, 2024
  2. changed the title [-]with `trailingSlash: always` loaders do not run if the trailing-slash is not present[/-] [+]when `trailingSlash: always` loaders do not run if the trailing-slash is not present[/+] on Jun 18, 2024
  3. schiller-manuel commented on Jun 19, 2024

    @schiller-manuel
    Collaborator

    I added a beforeLoad

    https://stackblitz.com/edit/tanstack-router-af56kj?file=src%2Fmain.tsx,src%2Froutes%2F__root.tsx,src%2Froutes%2Fabout.tsx&preset=node

    Accessing about/ works as expected:

    beforeLoad foo
    loader foo
    

    but accessing about without the trailing slash causes the following error in loader:

    Cannot read properties of undefined (reading 'foo')
    
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