[英]Accounts.onLogin with IronRouter
I'm trying to redirect user to a page after login. 我正在尝试在登录后将用户重定向到页面。 Trying to use Router.go from Accounts.onLogin callback: 尝试使用Accounts.onLogin回调中的Router.go:
Accounts.onLogin () ->
Router.go('users.new')
When I try this on the server I get TypeError: Object [object Object] has no method 'go'
当我在服务器上尝试这个时,我得到TypeError: Object [object Object] has no method 'go'
On the client I get Accounts.onLogin undefined
在客户端我得到Accounts.onLogin undefined
Well, you've got a problem here : 嗯,你在这里遇到了一个问题:
Accounts.onLogin
is undefined on the client because it is a server-only API. Accounts.onLogin
在客户端上未定义,因为它是仅服务器API。
UPDATE 15/06/2015 : this is no longer true, Accounts.onLogin
is now available on the client too. 更新2015年6月15日:这已不再适用, Accounts.onLogin
现在也可在客户端上使用。
Router.go is undefined on the server because redirecting with iron:router is a client-only API. Router.go在服务器上未定义,因为使用iron:router重定向是一个仅限客户端的API。
If you are using {{> loginButtons}}
you can try this workaround on the client : 如果您使用{{> loginButtons}}
,可以在客户端上尝试此解决方法:
Tracker.autorun(function(){
if(Meteor.user()){
// login handler
Router.go("users.new");
}
else{
// logout handler
}
});
If you are using a custom login form with Meteor.loginWithSomething
, you can perform the redirection in the success callback of the login method. 如果您使用Meteor.loginWithSomething
的自定义登录表单, Meteor.loginWithSomething
可以在登录方法的成功回调中执行重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.