Skip to content

Redirect loop with optional path params, layout route and index route #4715

@SashkaHavr

Description

@SashkaHavr

Which project does this relate to?

Router

Describe the bug

I'm falling into an infinite redirect loop using the following directory structure:

├── src/
│   ├── routes/
│   │   ├── {-$locale}/
│   │   │   ├── index.tsx
│   │   │   └── route.tsx
│   │   └── `__root.tsx`

Not posting codesandbox link here beacause it breaks the browser

Your Example Website or App

https://github.com/SashkaHavr/tsrouter-optional-path-params-repro

Steps to Reproduce the Bug or Issue

  1. pnpm install
  2. pnpm dev
  3. Visit http://localhost:3000/
  4. Look at server console output

Result: "render /{-$locale}/route.tsx" is infinitelly spammed in console and page is never opened

Expected behavior

Index page with default locale is opened

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.128.4/1.128.5
  • OS: Windows
  • Browser: Chrome
  • Bundler: vite
  • Bundler Version: 7.0.5

Additional context

Workaround:

  1. Move beforeLoad from /src/routes/{-$locale}/route.tsx into /src/routes/{-$locale}/index.tsx
  2. Delete /src/routes/{-$locale}/route.tsx

Result: Index page with default locale is opened

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions