CNode

koa-router 如何处理url没有的情况,默认redirect

问答
Ppetitspois发布于12 年前最后回复12 年前1 回复16664 浏览0 收藏

ACB64B28-C15A-4DCC-86F9-1CA270FB3C81.png 新手见谅404页面处理

查看回复

回复 (1)

G
GuoZhang#1·12 年前

自己做middleware吧, 比如:

app.use(function *notFound(next) {
  if (this.status == 404) {
    console.log(this.url, 'requested but no route matches.');
  } else {
    yield next;
  }
});
参与回复
登录后即可参与回复。登录