Skip to content
New issue

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

app.js中routes(router)似乎没对 #59

Closed
IanLew opened this issue Jul 22, 2019 · 3 comments
Closed

app.js中routes(router)似乎没对 #59

IanLew opened this issue Jul 22, 2019 · 3 comments

Comments

@IanLew
Copy link

IanLew commented Jul 22, 2019

我是初学者,提的可能不对,请原谅。这段代码好像没啥用,又或者是指向的代码有问题。

@zhangyuang
Copy link

@IanLew 贴具体代码,app.use(index.routes(), index.allowedMethods());的目的是注册路由

@IanLew
Copy link
Author

IanLew commented Aug 5, 2019

在生成的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}); }) }
如果我理解没错,这样子并不能成功吧

@IanLew
Copy link
Author

IanLew commented Sep 24, 2019

之前是照着一个教程做的,装的包是koa2-generator。刚刚我装的包是koa-generator,代码风格和之前的包也不一样。

@IanLew IanLew closed this as completed Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants