gpt4 book ai didi

ember.js - Ember 路由器 - 如何处理 404(未找到)路由?

转载 作者:行者123 更新时间:2023-12-02 12:05:58 24 4
gpt4 key购买 nike

我正在尝试找出如何使用 Ember.Router 处理应用程序中的无效路由。

目前,如果我输入无效路线,例如myapp.com/#FooBarDoesntExist,它将重定向到索引路由('/')。如果我可以定义它将路由到的 notFound 或 404 状态,以便我可以通知用户发生了什么,我希望它。而不是将它们扔在主页上。

最佳答案

处理这个问题的一个好方法是声明一个除了你的路由之外还映射所有可能的 URL 的路由。您可以在这里举个例子:http://jsfiddle.net/mbreton/r3C9c/

var App = Ember.Application.create();

App.Router.map(function(){
this.route('detail', {path: "detail"});
this.route('missing', { path: "/*path" });
});


App.MissingRoute = Em.Route.extend({
redirect: function () {
Em.debug('404 :: redirection to index');
this.transitionTo("index");
}
});

App.ApplicationView = Em.View.extend({
didInsertElement:function(){
$('#missingLink').on('click', function (e){
window.location.hash = "#/pepepepepep";
return false;
});
}
});

在此示例中,所有未知网址都重定向到索引路由。

关于ember.js - Ember 路由器 - 如何处理 404(未找到)路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com