gpt4 book ai didi

meteor - Iron-router 使用钩子(Hook)限制管理员访问

转载 作者:行者123 更新时间:2023-12-01 05:07:36 24 4
gpt4 key购买 nike

我的铁路由器有问题。

当我第一次加载页面/admin/deps 时,路由会正常工作。然后我通过单击链接转到任何其他页面,然后在控制台中返回/admin/deps/我得到“路由调度从未呈现。您是否忘记在 onBeforeAction 中调用 this.next()? "并且模板未呈现

但是..如果我使用热交换代码更改代码中的任何内容, meteor 会重新加载页面,在这种情况下,一切都按预期工作。

这是我的 Controller 和路线:

class @AdminRouteController extends RouteController
onBeforeAction: ->
console.log "onBeforeAction: #{@url}"
if Meteor.loggingIn()
@render 'loading'
else if !Meteor.userId() or !Meteor.user().hasAccess 'admin'
@render 'notFound'
else
@next()

class @AdminPagebleRouteController extends AdminRouteController
pageable: true
perPage: 20

limit: (name = null) ->
Session.get(varName(@, name)) || @perPage

incLimit: (name = null, inc = null) ->
inc ||= @perPage
Session.set varName(@, name), (@limit(name) + inc)

resetLimit: (name = null) ->
Session.set varName(@, name), null

loaded: (name = null) ->
true

onRerun: ->
console.log "onRerun: #{@url}"
@next()

Router.route '/admin', name: 'admin'
class @AdminController extends AdminRouteController
template: 'adminHome'
action: ->
document.title = i18n 'admin.title'
super()

Router.route '/admin/deps', name: 'deps'
class @DepsController extends AdminPagebleRouteController
template: 'deps'
perPage: 20

waitOn: ->
@subscribe 'adminDeps', @limit()

data: ->
deps: DepartmentsCollection.find()

loaded: ->
@limit() > DepartmentsCollection.find().count()

action: ->
document.title = i18n 'deps.title'
super()

onRun: ->
console.log "onRun: #{@url}"
@resetLimit()
@next()

load: ->
$('html, body').animate({ scrollTop: 0 }, 400)
$('.content').hide().fadeIn(1000)

这是路由无法正常工作时的控制台屏幕
enter image description here

这是javascript中的代码:
AdminRouteController = RouteController.extend({
onBeforeAction: function(){
console.log("onBeforeAction: " + this.url);
if(Meteor.loggingIn())
this.render('loading');
else if(!Meteor.userId() || !Meteor.user().hasAccess('admin'))
this.render('notFound');
else
this.next();
}
});

varName = function(inst, name){
name = name && ("_" + name || "");
return inst.constructor.name + name + "_limit";
}

AdminPagebleRouteController = AdminRouteController.extend({
pageable: true,
perPage: 20,

limit: function (name){
return Session.get(varName(this, name)) || this.perPage;
},
incLimit: function (name, inc){
inc = inc ? inc : this.perPage;
return Session.set(varName(this, name), (this.limit(name) + inc));
},
resetLimit: function (name){
return Session.set(varName(this, name), null);
},
loaded: function (name){
return true;
},
onRerun: function (){
console.log("onRerun: " + this.url);
this.next();
}
});

Router.route('/admin', name: 'admin');
AdminController = AdminRouteController.extend({
template: 'adminHome',
action: function(){
document.title = i18n('admin.title');
super();
}
});

Router.route('/admin/deps', name: 'deps');
DepsController = AdminPagebleRouteController.extend({
template: 'deps',
perPage: 20,

waitOn: function(){
this.subscribe('adminDeps', this.limit());
},
data: function(){
return { deps: DepartmentsCollection.find() };
},
loaded: function(){
return this.limit() > DepartmentsCollection.find().count();
},
action: function(){
document.title = i18n('deps.title');
super();
},
onRun: function(){
console.log("onRun: " + this.url);
this.resetLimit();
this.next();
},
load: function(){
$('html, body').animate({ scrollTop: 0 }, 400);
$('.content').hide().fadeIn(1000);
}
});

最佳答案

最后,我找到了答案,问题出在DepsController 中,在load() 中。功能。它在 onBeforeAction() 之前触发,也需要调用this.next ()

关于meteor - Iron-router 使用钩子(Hook)限制管理员访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27376480/

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