Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Routes generated for index #13

Closed
nakleiderer opened this issue Jun 7, 2022 · 1 comment
Closed

Inconsistent Routes generated for index #13

nakleiderer opened this issue Jun 7, 2022 · 1 comment

Comments

@nakleiderer
Copy link

nakleiderer commented Jun 7, 2022

When generating routes, flat-routes deviates from Remix's index routing. In Remix, routes/foo/index.tsx has a path of foo, but in flat-routes, it generates a path of foo/. This can cause form libraries to submit to incorrect routes and lead to other bugs in the app.

Input: One file at routes/foo._index.tsx

Expected:

<Routes>
  <Route file="root.tsx">
    <Route path="foo" index file="routes/foo/index.tsx" />
  </Route>
</Routes>

Actual:

<Routes>
  <Route file="root.tsx">
    <Route path="foo/" index file="routes/foo._index.tsx" />
  </Route>
</Routes>

(note the extra "/" character in the Actual vs. Expected)

Repro: https://stackblitz.com/edit/node-bszx6t?file=README.md

Workaround: Renaming foo._index.tsx to foo.tsx generates the expected routes.

@kiliman
Copy link
Owner

kiliman commented Jun 7, 2022

With remix-flat-routes you have to explicitly define your index routes.

There's a difference between flat-files and flat-folders. With flat-files the route name is the filename without the extension. With flat-folders the route name is the folder name, and the index.tsx file is the route file. Either way, you must include index (or _index) in the route name to make it an index route.

flat-files

foo.tsx => /foo
foo.index.tsx => /foo/index

flat-folders

foo/index.tsx => /foo
foo.index/index.tsx => /foo/index

@kiliman kiliman closed this as completed in f7eaa66 Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants