How to handle 'no route matched' in Ember.js and show 404 page?

后端 未结 5 413
无人共我
无人共我 2020-12-08 18:55

How can I handle the error

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

and show a custom 404 page?


Note: This questi

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 19:22

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

    .. 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.

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

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

提交回复
热议问题