bartezr
bartezr

Reputation: 789

Whats wrong with my meteor routing?

My simple form on http://localhost:3000/connectSubmit:

<template name="connectSubmit">
   <form>
     <input type="email" class="testf form-control" id="email" placeholder="Email here"><br>  
    <input type="submit" value="Submit" class="submit btn btn-primary"/>
  </form>
</template>

connect_submit.js:

Template.connectSubmit.events({
    'submit form': function(e) {
        Router.go('index');
    }
  });

router.js:

Router.configure({
  layoutTemplate: 'layout',
});

Router.map(function() {
  this.route('index', {path: '/'})
  this.route('/connectSubmit')
});

Index.html:

<template name="index">
      <a href="/connectSubmit" class="btn btn-default">Connect</a>
</template>

When i'm submitting form, url is: http://localhost:3000/connectSubmit? and no redirecting me to index page

Upvotes: 2

Views: 84

Answers (2)

codepawn
codepawn

Reputation: 57

Yes you need the prevent default code

Template.ConnectSubmit.events 'submit form': (e, tmpl) -> e.preventDefault() Router.go 'home'

here is your anwer link http://anwerforbartezr.meteor.com/

and

anwer's code https://github.com/codepawn/stack_over_flow/tree/master/anwer_0

have a good day :)

Upvotes: 1

saimeunt
saimeunt

Reputation: 22696

When you submit a form in HTML, the default behaviour will be to issue an HTTP POST request and reload the page, breaking the single page web app experience, what you need to do is preventing this default behaviour so happen :

Template.connectSubmit.events({
  'submit form': function(e) {
    e.preventDefault();
    Router.go('index');
  }
});

Upvotes: 1

Related Questions