How to create simple userProfile route in Meteor with Iron Router -
How to create simple userProfile route in Meteor with Iron Router -
i trying route current user's profile page using iron router, 'pathfor' spacebars helper not passing href attribute tag.
this template:
<div class="collapse navbar-collapse" id="navigation"> <ul class="nav navbar-nav"> {{#if currentuser}} <li><a href="{{pathfor 'requestsubmit'}}">submit request</a></li> <li><a href="{{pathfor 'userprofile'}}">view profile</a></li> {{/if}} </ul> <ul class="nav navbar-nav navbar-right"> {{> loginbuttons}} </ul> </div>
the href submit request button passing in fine, reason view profile href not getting passed in.
my router.js follows:
router.route('/users/:_id', { name: 'userprofile', data: function() { homecoming meteor.users.findone(this.params._id); } });
in app, routing single "request" page (i created collection called requests) doing
router.route('/requests/:_id, { name: 'requestpage', data: function() { homecoming requests.findone(this.params._id); } });
this routes correctly single request requests collection, confused why userprofile route doesn't same.
also, tried forcefulness functionality creating click event on template:
template.header.events({ 'click .userprofile': function(e) { e.preventdefault(); var user = meteor.user(); router.go('userprofile', {_id: user._id}); } });
..and passed right href in template.
any help on appreciated!
the userprofile
route needs id
parameter. when phone call pathfor
in template route name effort extract parameters current context. because context isn't user (it's request?) end invalid path.
you can set context inline:
class="lang-html prettyprint-override"><li><a href="{{pathfor 'userprofile' data=currentuser}}">view profile</a></li>
alternatively, can set context outside of phone call using with
:
{{#with currentuser}} <li><a href="{{pathfor 'userprofile'}}">view profile</a></li> {{/with}}
meteor iron-router spacebars
Comments
Post a Comment