如何处理 Ember.js 中的“无路由匹配"并显示 404 页面? [英] How to handle 'no route matched' in Ember.js and show 404 page?

查看:20
本文介绍了如何处理 Ember.js 中的“无路由匹配"并显示 404 页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何处理错误

Uncaught Error: No route matched the URL '...'

并显示自定义 404 页面?

and show a custom 404 page?

注意:这个问题之前和几个月前回答 - 但不再工作了.

Note: This question was asked before and answered several months ago - but does not work anymore.

推荐答案

App.Router.map(function() {
  //set up all of your known routes, and then...
  this.route("fourOhFour", { path: "*path"});
});

... 定义您的 FourOhFourRoute 以显示您选择的未找到路由"消息.您将能够访问fourOhFour 路由中最初请求的路径作为路径参数.

.. where you have your FourOhFourRoute defined to show the "no route found" message of your choosing. You will be able to access the originally requested path in the fourOhFour route as the path parameter.

只是为了清楚起见——这个答案是在其他人被报告不再工作之后提出的.

just for clarity -- this answer came after the others were reported not to work anymore.

编辑 2:我已经更新了答案以反映 Yehuda Katz 的评论(如果我有错,请 LMK).

EDIT 2: I've updated the answer to reflect Yehuda Katz's comment (if I have it wrong, please LMK).

这篇关于如何处理 Ember.js 中的“无路由匹配"并显示 404 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆