我对所有页面使用相同的布局。但是,当用户登录时,我的layout.js不再有效,特别是Template.layout.rendered函数。
我该如何处理?
Router.configure({
templateNameConverter: "upperCamelCase",
routeControllerNameConverter: "upperCamelCase",
layoutTemplate: "layout",
notFoundTemplate: "notFound",
loadingTemplate: "loading"
});
var publicRoutes = ["home_public", "home-public", "login", "register", "forgot_password", "reset_password"];
var privateRoutes = ["home-private", "orders", "orders.insert", "orders.details", "orders.edit"];
Router.ensureLogged = function() {
if(!Meteor.user()) {
// user is not logged in - redirect to public home
this.redirect("home_public");
return;
} else {
// user is logged in - check role
this.next();
}
};
Router.ensureNotLogged = function() {
if(Meteor.user())
this.redirect("home_private");
else
this.next();
};
Router.onBeforeAction(Router.ensureNotLogged, {only: publicRoutes});
Router.onBeforeAction(Router.ensureLogged, {only: privateRoutes});
答案 0 :(得分:0)
似乎Meteor或Iron-Router(我怀疑Meteor)有一些问题。
**我的修复是为私人页面和公共页面使用单独的布局,例如 layout_private 和 layout_public 。 **
Meteor,当在登录/注销之间切换时,不会重新执行Template.layout.render(如果使用相同的布局),并且它之间会以某种方式丢失javascript事件侦听器。