我需要使用同一窗口使用 Meteor JS 时,单击提交或登录按钮如何导航到新页面。请帮助我写作。当用户提交表单页面时,导航到 admindetails.html页面。我正在使用路由器软件包,而HTML页面和客户端代码如下。我的目的是在用户登录加载中的另一个模板>同一窗口中的另一个模板,动态 .please。请帮助我。
Here is html page
<template name="body">
<div class="bgbody">
<div align="center">
<form id="login-form" action="/admindetails">
<table>
<p class="admin">Admin Login</p>
<tr>
<td><p for="username">Admin Name</p></td>
<td><input type="text" id="username" name="username" placeholder="UserName"></td>
</tr>
<tr>
<td><p for="password">Password</p></td>
<td><input type="password" id="pwd" name="password" placeholder="password"></td>
</tr>
<td></td><td><input class="btn btn-success" type="submit" value="Log In"></td>
</table>
</form>
</div>
</div>
</template>
这是客户端代码
if (Meteor.isClient)
{
Meteor.Router.add({
'/admindetails':'admindetails'
})
Template.body.events
({
'submit #login-form' : function (e,t)
{
/* template data, if any, is available in 'this'*/
if (typeof console !== 'undefined')
console.log("You pressed the button");
e.preventDefault();
/*retrieve the input field values*/
var email = t.find('#username').value
, password = t.find('#pwd').value;
console.log(email);
Meteor.loginWithPassword(email, password, function (err)
{
if (err)
{
console.log(err);
alert(err.reason);
Session.set("loginError", true);
}
else
{
console.log(" Login Success ");
Meteor.Router.to("/admindetails");
}
});
}
});
}
如果使用推荐的铁路由器,则使用go
方法:
Router.go('/articles/example');
或:
Router.go('showArticle', {name: 'example'});
如果使用旧路由器,请使用:
Meteor.Router.to('/articles/example');
如果您不使用任何路由器,请立即开始。同时,使用石器时代方法:
window.location.href = '...';