1
我的[email protected]
應用程序具有以下結構。我使用[email protected]
的路由:與koa路由器不在單獨文件中的子路徑
./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;
我的/hello
路線上得到Not Found
錯誤。
相關版本:
"dependencies": {
"koa": "^2.0.0-alpha.7",
"koa-router": "^7.0.1",
},
這是一個與koa-router
V7.1.0相同。
謝謝你的幫助!