We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
我是初学者,提的可能不对,请原谅。这段代码好像没啥用,又或者是指向的代码有问题。
The text was updated successfully, but these errors were encountered:
@IanLew 贴具体代码,app.use(index.routes(), index.allowedMethods());的目的是注册路由
Sorry, something went wrong.
在生成的app.js中,const routes = require('./routes'),routes目录下有很多路由,然后app.js中有这么段代码routes(router)。我的理解是这段代是为注册routes目录下的所有路由,我不理解的是下面的路由文件都是这样的: module.exports = (router) => { router.get('/welcome', async function (ctx, next) { ctx.state = { title: 'koa2 title' }; await ctx.render('welcome', {title: ctx.state}); }) } 如果我理解没错,这样子并不能成功吧
const routes = require('./routes')
routes(router)
module.exports = (router) => { router.get('/welcome', async function (ctx, next) { ctx.state = { title: 'koa2 title' }; await ctx.render('welcome', {title: ctx.state}); }) }
之前是照着一个教程做的,装的包是koa2-generator。刚刚我装的包是koa-generator,代码风格和之前的包也不一样。
No branches or pull requests
我是初学者,提的可能不对,请原谅。这段代码好像没啥用,又或者是指向的代码有问题。
The text was updated successfully, but these errors were encountered: