0
我想使用ui路由器来处理与流星角应用程序的路由。我下面流星WhatsApp的教程here角流星ui路由器不加载
这里是与UI的路由器打交道的代码
login.controller.js
export default class LoginController extends Controller {
login() {
Meteor.loginWithFacebook({}, function(err){
if (err) {
throw new Meteor.Error('Facebook login error')
} else {
var user = Meteor.users.find().fetch();
this.$state.go('tabs');
}
});
}
}
LoginController.$inject = ['$state'];
routes.js
class RoutesConfig extends Config {
configure() {
this.$stateProvider
.state('login', {
url: '/login',
templateUrl: 'client/templates/login.html',
controller: 'LoginController as login'
})
.state('tabs', {
url: '/tabs',
templateUrl: 'client/templates/tabs.html'
});
this.$urlRouterProvider.otherwise('login');
}
}
RoutesConfig.$inject = ['$stateProvider', '$urlRouterProvider'];
class RoutesRunner extends Runner {
run() {
this.$rootScope.$on('$stateChangeError', (...args) => {
const err = _.last(args);
if (err === 'AUTH_REQUIRED') {
this.$state.go('login');
}
});
}
}
RoutesRunner.$inject = ['$rootScope', '$state'];
export default [RoutesConfig, RoutesRunner];
登录屏幕后,应用程序应该转到另一个v但是我在控制台中收到了这条消息。
Exception in delivering result of invoking 'login': TypeError: Cannot read property 'go' of undefined
at http://localhost:3000/app/app.js?hash=8f1e5c5eb688417de85584fbdefdc289814dac42:151:17
at Accounts.callLoginMethod.userCallback (http://localhost:3000/packages/accounts-oauth.js?hash=ac90001ebf17b2b7e1ebf1370330775b19248242:165:7)
at http://localhost:3000/packages/accounts-base.js?hash=9a2df45ebeba9d14f693547bc91555a09feda78e:322:26
at http://localhost:3000/packages/underscore.js?hash=27b3d669b418de8577518760446467e6ff429b1e:794:19
at loggedInAndDataReadyCallback (http://localhost:3000/packages/accounts-base.js?hash=9a2df45ebeba9d14f693547bc91555a09feda78e:434:5)
at MethodInvoker._callback (http://localhost:3000/packages/meteor.js?hash=ae8b8affa9680bf9720bd8f7fa112f13a62f71c3:1105:22)
at MethodInvoker._maybeInvokeCallback (http://localhost:3000/packages/ddp-client.js?hash=b5f1b97df6634673c68f37914ae9f4c3231c438e:3541:12)
at MethodInvoker.receiveResult (http://localhost:3000/packages/ddp-client.js?hash=b5f1b97df6634673c68f37914ae9f4c3231c438e:3561:10)
at Connection._livedata_result (http://localhost:3000/packages/ddp-client.js?hash=b5f1b97df6634673c68f37914ae9f4c3231c438e:4681:9)
at onMessage (http://localhost:3000/packages/ddp-client.js?hash=b5f1b97df6634673c68f37914ae9f4c3231c438e:3369:12)
那它应该是$ urlRouterProvider.otherwise( '/登录')。 –
我同意,但这不是问题。 'this. $ state.go('link')'导致$ state未定义的错误。 –
如果你可以把这件事情变成一个笨蛋,那真的很棒 –