kiliman / remix-flat-routes

Remix package to define routes using the flat-routes convention
MIT License
695 stars 24 forks source link

Submitting forms in parent layout routes tries posting to wrong action. #85

Closed MoSattler closed 10 months ago

MoSattler commented 10 months ago

Hey, I posted the same issue in the remix repo (https://github.com/remix-run/react-router/issues/11024), but someone mentioned this could be an issue with the flat-route package as well. I am using "remix-flat-routes": "^0.6.2".

What version of Remix are you using?

2.2.0

Are all your remix dependencies & dev-dependencies using the same version?

Steps to Reproduce

I have a layout route on my-parent.$someParam.tsx which adds a form and a action to handle the form.

inside that route there are three children:

Now, when I am submitting the form on /my-parent/some-value/my-child, everything works as expected.

But if I am on /my-parent/some-value/my-child?index, and I try submit, I get the following error:

405 Error: Route "routes/my-parent._index.tsx" does not have an action, but you are trying to submit to it. To fix this, please add an action function to the route.

Expected Behavior

Forms should always submit to the action in their route, not some other route

Actual Behavior

For some reason, if i am on the ?index path of some child route, actions of parent layout routes also try to post on their respective index routes

MoSattler commented 10 months ago

As a temporary fix I have done this in my-parent.$someParam.my-child._index.tsx:

export { action } from "#my-parent.$someParam.my-child"
kiliman commented 10 months ago

As I stated in https://github.com/remix-run/react-router/issues/11024 this is how Remix works.

MoSattler commented 10 months ago

As I stated in remix-run/react-router#11024 this is how Remix works.

Not quite, it is a bug in remix.