Meteor iron router的正确语法';什么路线?
我在Meteor JS应用程序中为我的iron路由器签出路由提供了以下代码。我正在尝试将不推荐使用的Router.map转换为新的Router.route语法,但很难使onBeforeAction和onAfterAction正常工作。以下代码块的正确Router.route语法是什么Meteor iron router的正确语法';什么路线?,meteor,iron-router,Meteor,Iron Router,我在Meteor JS应用程序中为我的iron路由器签出路由提供了以下代码。我正在尝试将不推荐使用的Router.map转换为新的Router.route语法,但很难使onBeforeAction和onAfterAction正常工作。以下代码块的正确Router.route语法是什么 Router.map(function () { // sign-out the user then redirect them to the home page this.route('signOut'
Router.map(function () {
// sign-out the user then redirect them to the home page
this.route('signOut', {
path: '/sign-out',
onBeforeAction: function () {
if (Meteor.userId()) {
Meteor.logout()
}
this.next();
},
onAfterAction: function () {
this.redirect('/');
}
});
});
我认为应该添加waitOn函数,因为如果不提前订阅,一开始可能不会有Meteor.user()对象
Router.route('/sign-out', function() {
//here you put things you wanna render, it's empty since you just want to logout and redirect
}, {
name: 'signOut',
onBeforeAction: function () {
if (Meteor.userId()) {
Meteor.logout()
}
this.next();
},
onAfterAction: function () {
Router.go('/');
}
});