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

Actions in app/routes/index.js do not work #10

Open
knowler opened this issue Oct 18, 2022 · 2 comments
Open

Actions in app/routes/index.js do not work #10

knowler opened this issue Oct 18, 2022 · 2 comments

Comments

@knowler
Copy link

knowler commented Oct 18, 2022

If I submit a <remix-form> inside of app/routes/index.js where I also have an action defined, I receive the following error.

You're trying to submit to a route that does not have an action.  To fix this, please add an `action` function to the route for [/]

It seems to expect the action to be in app/root.js. I’m not sure how this compares with regular Remix or if this is just an issue with this implementation.

app/routes/index.js
/** 
 * @param {import('enhance-remix').ActionFunctionArgs}
 */
export async function action({ request }) {
  const formData = await request.formData();

  console.log(formData.get('message'));
}

/**
 * @type {import("@enhance/types").EnhanceElemFn}
 */
export default function Index({ html }) {
  return html`
    <main>
      <remix-form action="/" method="POST">
        <label>Message <input name="message"></label>
        <button>Send</button>
      </remix-form>
    </main>
  `;
}
@jrestall
Copy link

I wonder if this is related to remix-run/react-router#9486 and might be fixed by updating the @remix-run/router dependency once released. Maybe you could even use npm overrides to test this theory by setting @remix-run/router to 1.0.3-pre.1.

@jacob-ebey
Copy link
Owner

You need to submit to an index route: /?index, otherwise you are submitting to the parent route.

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

3 participants