gpt4 book ai didi

meteor 和铁路由器 : raise 404 when id doesn't exist

转载 作者:行者123 更新时间:2023-12-04 10:38:29 24 4
gpt4 key购买 nike

我正在为我的网址使用 Iron Router,我有以下路线:

this.route('regionEdit', {
path: '/region/:_id',
waitOn: function() {
return Meteor.subscribe('region', this.params._id);
},
data: function() {
return Regions.findOne({
_id: this.params._id
});
}
});

当我使用此路径时,这很好用 http://example.com/region/xgok3Etc5mfhtmD7j
哪里 xgok3Etc5mfhtmD7j_id的地区。但是,当我访问 http://example.com/region/whatever 时,页面呈现正常,但没有数据。

如何为此引发 404 错误?

最佳答案

不是 404,但您可以通过执行此类操作来呈现未找到的页面。

this.route('regionEdit', {
path: '/region/:_id',
waitOn: function() {
return Meteor.subscribe('region', this.params._id);
},
data: function() {
var region = Regions.findOne({
_id: this.params._id
});
if(!region)
this.render("notFound");
else
return region;
}
});

关于 meteor 和铁路由器 : raise 404 when id doesn't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23705661/

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