Search code examples
javascriptmeteoriron-router

Changing default /submit route in Meteor


The Discover Meteor book develops a sample appliction called Microscope, with the Github repo here: https://github.com/DiscoverMeteor/Microscope

In it, the submit form seems to be defaulted (as nowhere can a see a link to /submit in the html).

<input type="submit" value="Submit" class="btn btn-primary"/>

Router.route('/submit', {name: 'postSubmit'});

How can I call this something else, eg: /postSubmit ?


Solution

  • To accomplish this you could change the route path to /postSubmit

    Router.route('/postSubmit', {name: 'postSubmit'});
    

    This works because the code is using pathFor, which takes the path name provided (postSubmit) to look up the corresponding route path (/postSubmit).

    For the example below the href will be substituted with /postSubmit

    <a href="{{pathFor 'postSubmit'}}">Submit Post</a>
    

    and the outcome will be:

    <a href="/postSubmit">Submit Post</a>