0

我查看并遵循了以下指南:

https://github.com/koajs/koa

https://github.com/alexmingoia/koa-router

https://github.com/saadq/koa-combine-routers/tree/next

尝试使用命名参数时出现 404 Not Found。我错过了什么?

服务器.js

const Koa = require('koa');
const router = require('./routes');

const app = new Koa()

app.use(router);

app.listen(8080);

module.exports = app;

路线/index.js

const combineRouters = require('koa-combine-routers');
const paramRouter = require('./param');

const router = combineRouters([
  paramRouter
])

module.exports = router;

路线/param.js

const Router = require('koa-router');
const router = new Router()

router.get('/noParam/', async (ctx, next) => {
    ctx.body = ctx
});

router.get('/param/:jsonObj', async (ctx, next) => {
    ctx.body = ctx.params.jsonObj;
});

module.exports = router;

包.json

"dependencies": {
    "iorejson": "^0.1.1",
    "koa": "^2.2.0",
    "koa-combine-routers": "^1.0.0",
    "koa-router": "^7.1.1",
}

GET http://localhost:8080/noParam-> 200

GET http://localhost:8080/param?jsonObj=foo-> 404

4

1 回答 1

0

我用来调用的方法是错误的。

GET http://localhost:8080/param/foo-> 200

于 2017-05-11T21:28:12.417 回答