路由调度从未呈现.您是否忘记在onBeforeAction中调用this.next()
Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction?
我现在正在Meteor中执行注销功能,我注意到了一些奇怪的事情。当我在登录页面上时,甚至在注销并重定向到登录页面时,我的 Google 控制台上会出现错误:
路由调度从未呈现。您是否忘记在onBeforeAction中调用this.next()?
这是我的代码:
router.js
var routerExcepts = [
"login",
"register"
];
Router.onBeforeAction(function() {
if (Router.current().route.getName() != "adminlogin.:_id") {
if (!Meteor.userId()) {
return this.redirect("/login");
} else {
this.next();
}
}
}, {
except: routerExcepts
});
home.html:
<template name="home">
<div class="container">
<a href="#" id="item-logout" class="btn btn-default btn-lg btn-block">Logout</a>
</div>
</template>
home.js:
Template.home.events({
"click #item-logout": function() {
Meteor.logout();
}
});
有人知道我的代码是怎么回事吗?我知道这与其他问题重复,我尝试了针对这些已回答问题提供的解决方案,但它不能解决我的问题。
提前谢谢。
您不需要将其设置为返回值,我认为这可能会导致您的问题,替换
return this.redirect("/login");
跟
this.redirect("/login");
如果您仍然收到错误,请尝试将"this.redirect"替换为"Router.go"(如果我没记错的话,无论如何,这个.redirect代理都在引擎盖下),如下所示:
Router.go("/login");
你也可以删除 else 以确保始终触发 this.next():
Router.onBeforeAction(function() {
if (Router.current().route.getName() != "adminlogin.:_id") {
if (!Meteor.userId())
Router.go("/login");
this.next();
}
}
尝试将this.next()
置于条件之外:
Router.onBeforeAction(function() {
if (Router.current().route.getName() != "adminlogin.:_id") {
if (!Meteor.userId()) {
return this.redirect("/login");
}
}
this.next();
}
相关文章:
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 如何从Java/scala调用js美化程序
- 如何调用这个匿名 JavaScript 函数
- 如何从模块链中调用函数.导出到节点中
- 我需要从php调用javascript或jquery
- Chrome开发工具(如何知道我在调用哪个javascript对象)
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- node.js:setInterval()正在跳过调用
- 如何在单击复选框后调用控制器方法
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 使用Google Visualization动态调用构造函数
- 如何在webView,Android中从@JavascriptInterface方法调用Javascript
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 调用函数内部的函数
- 函数未在Object.keys或Object.getOwnPropertyNames下列出,但可以调用
- Javascript/jQuery中的并行Ajax调用
- 同步调用,直到用户通过angular验证为访问者