我對所有網頁使用相同的佈局。但是,當用戶登錄時,我的layout.js不再有效,特別是Template.layout.rendered函數。鐵路由器(流星1.0)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});
我有舊版本的鐵路由器和重定向的一些問題。它主要與反應性停止工作有關,只是爲了檢查 - 如果在重定向發生(未)時重新加載瀏覽器,您的代碼是否工作? – 2014-12-03 22:01:47
Btw。你也可以嘗試用Router.go()替換this.redirect()。 – 2014-12-03 22:02:07
不,重新啓動瀏覽器沒有幫助。 – mfr 2014-12-04 00:15:59