【发布时间】:2018-06-15 10:09:09
【问题描述】:
我正在使用 NodeJS、Express 和 Handlebars(模板引擎)来构建 Web 应用程序。目前,我正在尝试在用户输入不存在的 URL 时(或当他们可能无权访问它时)自动重定向用户。
以下返回索引页面:
router.get('/', (req, res) => {
res.render('index/index');
});
但是我该如何做这样的事情:
router.get('/:ThisCouldBeAnything', (req, res) => {
res.render('errors/404');
});
以下示例来自 Github:
假设我输入了这个网址:
https://github.com/thispagedoesnotexist
它会自动返回 404。如何在我的应用程序中实现它?
提前致谢。
【问题讨论】:
标签: node.js express handlebars.js http-status-code-404