路由地址报错404
来源:3-2 Koa异步async

慕的地3227104
2018-11-25
const router = require(‘koa-router’)()
router.get(’/’, async (ctx, next) => {
global.console.log(‘index’)
await ctx.render(‘index’, {
title: ‘Hello Koa 2!’
})
})
router.get(’/string’, async (ctx, next) => {
ctx.body = ‘koa2 string’
})
router.get(’/json’, async (ctx, next) => {
ctx.body = {
title: ‘koa2 json’
}
})
router.get(’/testAsync’, async (ctx) => {
const a = await new Promise((resolve) => {
setTimeout(() => {
resolve(‘a’)
}, 1000)
})
ctx.body = {
a
}
})
module.exports = router
老师,为什么我写的那个/testAsync,接口会报404呢,我以为我写错了,于是我把上面的实例代码复制了一次,改了个接口名字,还是报404,这是什么原因啊?
写回答
2回答
-
慕粉3226958
2019-06-11
怎么解决的 我遇到了相同的问题
012019-06-11 -
快乐动起来呀
2018-11-25
其他接口有生效吗,应该是这个路由文件没有在app.js引入并加到到路由表,对照源码看下哈
022019-07-09
相似问题