我需要点击提交或登录按钮,如何使用meteor js 导航到具有相同窗口的新页面.请帮我怎么写.当用户提交表单页面导航到admindetails.html页面时.我正在使用路由器包,html页面和客户端代码如下.我的意图是在用户登录后动态地在同一窗口中加载另一个模板.请帮助我.
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>
Run Code Online (Sandbox Code Playgroud)
这是客户端代码
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");
}
});
}
});
}
Run Code Online (Sandbox Code Playgroud)
如果您使用推荐的Iron Router,则使用以下go方法:
Router.go('/articles/example');
Run Code Online (Sandbox Code Playgroud)
要么:
Router.go('showArticle', {name: 'example'});
Run Code Online (Sandbox Code Playgroud)
如果您使用旧路由器,请使用:
Meteor.Router.to('/articles/example');
Run Code Online (Sandbox Code Playgroud)
如果您不使用任何路由器,请立即开始.在此期间,使用石器时代方法:
window.location.href = '...';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5031 次 |
| 最近记录: |