混音运行 - 提交动作并获取“ root” - 没有行动,但您正在尝试提交

发布于 2025-02-05 00:58:21 字数 1365 浏览 5 评论 0原文

我在混音运行中派遣我的诉讼遇到了一些麻烦 - 我还有一个带有购物车中所有数据的旁边 - 我有一个整理所有数据的表格 - 当我希望创建结帐时我想从此处请求的数据中调用操作,

<Form action='/products' method="post">
                {cart.map((item, idx) => ( 
                <div key={idx}>
                <input readOnly value={item.product.id} type="hidden" name="id"/>
                <input readOnly value={item.quantity}  type="hidden" name="quantity"/>
                </div>

                ))}
                
                <button 
                className="mr-2 m"
                >              Add to Cart
                </button>
</Form>


export const  action: ActionFunction = async ({request}) => {
  // get the form data from the POST
  const formData = await request.formData()
  const id = formData.getAll('id')
  const quantity = formData.getAll('quantity')

  const newObj = id.map((data, index) => {
    
    return  { variantId: data, quantity: quantity[index] }

  } )

  

  const cart = await createCheckout(newObj)
  return cart
}

我的结帐URL是生成的,因此我需要等待响应。当我提交时,我会得到一个405错误,说不允许的方法

react_devtools_backend.js:4026 Route "root" does not have an action, but you are trying to submit to it. To fix this, please add an `action` function to the route

是错误消息,但是我似乎找不到文档中的任何地方如何在路由中添加操作函数?因为我发誓我已经在这样做了吗?

Im having a bit of trouble getting my action to dispatch in remix run - I have an Aside which comes out with all the data from my shopping cart - I have a form that collates all the data - and when I want the checkout to be created I want to call the action

<Form action='/products' method="post">
                {cart.map((item, idx) => ( 
                <div key={idx}>
                <input readOnly value={item.product.id} type="hidden" name="id"/>
                <input readOnly value={item.quantity}  type="hidden" name="quantity"/>
                </div>

                ))}
                
                <button 
                className="mr-2 m"
                >              Add to Cart
                </button>
</Form>


export const  action: ActionFunction = async ({request}) => {
  // get the form data from the POST
  const formData = await request.formData()
  const id = formData.getAll('id')
  const quantity = formData.getAll('quantity')

  const newObj = id.map((data, index) => {
    
    return  { variantId: data, quantity: quantity[index] }

  } )

  

  const cart = await createCheckout(newObj)
  return cart
}

From the data that is requested here my checkout URL is generated so i need to wait for the response. When I submit i get a 405 error saying method not allowed

react_devtools_backend.js:4026 Route "root" does not have an action, but you are trying to submit to it. To fix this, please add an `action` function to the route

This is the error message but I cant seem to find anywhere in the docs how to add a action function to the route? because I swear I am already doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗琴音 2025-02-12 00:58:21

tldr;

我遇到了同样的问题,并能够通过更改我的动作URL来解决“最后”索引。

详细信息

我的“产品”文件位于/products/index.tsx上,

以进行混音,以免我指的是root我必须使用以下操作路线:

action =“/products?index”

仅使用action =“/products”单独使用。

一旦我添加索引在操作中,一切都按预期工作。

根据混音文档:

如果要发布索引路由使用?在操作中使用索引:action =“/accounts?index” method =“ post”/&gt;

有关更多详细信息,请参见: https://remix.run/docs/docs/en/en/v1 /api/remix#form

另外,请注意,大多数情况下,您可以删除操作,并且表单将使用渲染的路线。

tldr;

I ran into this same issue and was able to solve by changing my action url to include ?index at the end.

Details

My "products" file was located at /products/index.tsx

In order for remix to not think I was referring to root I had to use the following action route:

action="/products?index"

Just using action="/products" alone did not work.

Once I added the ?index part to the action, everything worked as expected.

According to the remix docs:

If you want to post to an index route use ?index in the action: action="/accounts?index" method="post" />

For more details, see: https://remix.run/docs/en/v1/api/remix#form

Also, note that most of the time you can just leave off the action and the Form will use the route in which it is rendered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文