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

路由 resources 模式下无法访问到destroy #3413

Closed
ghost opened this issue Jan 18, 2019 · 4 comments
Closed

路由 resources 模式下无法访问到destroy #3413

ghost opened this issue Jan 18, 2019 · 4 comments

Comments

@ghost
Copy link

ghost commented Jan 18, 2019

router 路由设置

router.resources('qrcode', '/api/qrcode', controller.qrcode);

controller 控制器设置

`'use strict';

const Controller = require('egg').Controller;

class QrcodeController extends Controller {
async index() {
const { ctx } = this;
const { page } = ctx.request.query;
ctx.boyd = '这里可以使用';
}
async destroy() {
const { ctx } = this;
ctx.body = 1;
}
}

module.exports = QrcodeController;
`

我在前台使用这个路由的时候
通过get 可以访问到 index
通过 DELETE 访问不到 destroy
如果将路由改为
router.del('qrcode', '/api/qrcode', controller.qrcode.destroy);
可以访问,有点搞不清楚问题在哪,好像put也有这个问题,有人能告诉我哪里错了吗?

具体的 router.resources 的使用文档看这里:https://eggjs.org/zh-cn/basics/router.html#restful-%E9%A3%8E%E6%A0%BC%E7%9A%84-url-%E5%AE%9A%E4%B9%89

我确定已经参考文档使用了但还是存在问题
路由设置
image

控制器设置

image

postman请求结果

image

但是同路由下的index可以访问

image

@popomore
Copy link
Member

Delete 后面要带 id

@egg-bot
Copy link

egg-bot commented Jan 18, 2019

Hello @yioMe. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@yioMe,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

@okoala
Copy link
Member

okoala commented Jan 18, 2019

具体的 router.resources 的使用文档看这里:https://eggjs.org/zh-cn/basics/router.html#restful-%E9%A3%8E%E6%A0%BC%E7%9A%84-url-%E5%AE%9A%E4%B9%89

@okoala
Copy link
Member

okoala commented Jan 19, 2019

@yioMe 要这么调
DELETE: api/qrcode/1
id 不是写在 body 里的,是写在 url 上

@ghost ghost closed this as completed Jan 19, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants