Question

I need when click on submit or login button how to navigate to new page with same window using meteor js. please help me how to write. when user submit the form page navigate to admindetails.html page .I am using router package and the html page and client code is below. My intention is after user login load another template in same window dynamically .Please help me.

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>

Here is the Client code

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");
     }
    });
    }
  });
}
Was it helpful?

Solution

If you use the recommended Iron Router, you use the go method:

Router.go('/articles/example');

or:

Router.go('showArticle', {name: 'example'});

If you use the old Router, use:

Meteor.Router.to('/articles/example');

If you don't use any router, start right now. In the meantime, use the stone-age method:

window.location.href = '...';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top