2

私のkoa@nextアプリは次の構造を持っています。私はkoa-router@nextルーティングに使用しています:

./app.js

const Koa = require('koa');
const router = require('koa-router')();

const index = require('./routes/index');

const app = new Koa();

router.use('/', index.routes(), index.allowedMethods());
app
  .use(router.routes())
  .use(router.allowedMethods());

module.exports = app;

./routes/index.js

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

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

router.get('/hello', (ctx, next) => {
  ctx.body = 'Hello, World!';
});

module.exports = router;

ルートNot Foundでエラーが発生します。/hello

依存バージョン:

"dependencies": {
  "koa": "^2.0.0-alpha.7",
  "koa-router": "^7.0.1",
},

koa-routerv7.1.0でも同様です。

ご協力ありがとうございました!

4

1 に答える 1