我需要了解Meteor中路由器包导航的用法。当我需要如下所述的导航时:
我做了一个示例应用程序。在这个应用程序包含用户登录。当用户登录时,它将成功转到另一个页面,即“main”这里main是模板名称。
代码:
Meteor.loginWithPassword(email, password, function (err) {
if (err) {
alert(err.reason);
} else {
console.log(" Login Success ");
//Here go another Page i.e Main(main is template name) using router Package
Router.go('main');//using this method for navigation but it cames error as shown below
}
});
路由器代码:
Meteor.Router.add({
'/':'main',
})
错误:
[14:27:51.895] "Exception in delivering result of invoking 'login': ["submit #login-form"]/<@http://localhost:3000/client/views/login.js?c31d1b51f33bf5de460100e196ef33eb38475f65:24
_.once/<@http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:801
Accounts.callLoginMethod/loggedInAndDataReadyCallback@http://localhost:3000/packages/accounts-base.js?7b90b1939a52b5c6ad91265df4dd167bd5f4ebdb:467
Meteor.bindEnvironment/<@http://localhost:3000/packages/meteor.js?148e9381d225ecad703f4b858769b636ff7a2537:822
._maybeInvokeCallback@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:3782
.receiveResult@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:3802
._livedata_result@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:4805
Connection/onMessage@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:3647
._launchConnection/self.socket.onmessage/<@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:2709
_.forEach@http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156
._launchConnection/self.socket.onmessage@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:2708
SockJS</REventTarget.prototype.dispatchEvent@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:150
SockJS</SockJS.prototype._dispatchMessage@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:1135
SockJS</SockJS.prototype._didMessage@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:1193
SockJS</SockJS.websocket/that.ws.onmessage@http://localhost:3000/packages/livedata.js?502d55e7a7449f770e46330161cb7bd525c4417a:1340
"
答案 0 :(得分:0)
Router.go(routeName)
是Iron-Router中的正确功能,但您使用的是Router。此包中的正确函数为Meteor.Router.to('/');
答案 1 :(得分:0)
旧的router
软件包很久以前就被弃用了,而Meteor的客户端代码从那时起就发生了巨大的变化。如果您现在使用旧路由器,您将收到错误。
正确的解决方案是使用当前标准router
替换iron-router
包。然后你可以使用Router.go('main')
。有关文档,请参阅Iron Router's Github page。