سؤال

to learn meteor, I'm following Sacha Greif's book 'Discovering Meteor'. The current source code is reflected here-> https://github.com/stopachka/meteor-hackernews

Right now, I'm trying to add a 'discuss' link to the post_item, which is supposed to render the single post_item.

<template name="postItem">
  <div class="post">
    <div class="post-content">
      <h3><a href="{{url}}">{{title}}</a><span>{{domain}}</span></h3>
    </div>
    <a href="{{postPagePath title}}" class="discuss btn">Discuss</a>
  </div>
</template>

The router looks like so ->

Meteor.Router.add
  '/': 'postsList'
  '/posts/:_id':
    to: 'postPage'
    and: (id) ->
      Session.set('currentPostId', id)

Currently, If I type in to the browser

localhost:3000/posts/foobarid

It renders the corresponding post

But when i add the {{postPagePath title}}, the discuss button does not even show the href property. I'm assuming it's because it's not rendering anything.

Super new to Meteor here, any guidance greatly appreciated

هل كانت مفيدة؟

المحلول

A couple of points to note here:

First, the router package you are using with the tutorial, Meteor Router, has been deprecated in favor of a now-canonical routing package for Meteor, Iron Router. You can see this noted on the Meteor Router github page here, and you can find the Iron Router specifications here. I suspect you may be using an older version of the Discover Meteor book as well, as it now covers Iron Router in detail. If at all possible, I'd try to get my hands on a version of the book covering Iron Router as it will be the standard for the foreseeable future.

Second, you are correct that that href="" property is not showing up because it is not rendering anything. Specifically, in Meteor 0.8+, if the value of an attribute returns null, undefined or false, the attribute itself is removed. Read more here.

Lastly, while I'm not up to speed on the details of Meteor Router it looks on quick inspection like you would want to pass PostPagePath the id and not the title of the post, e.g. {{PostPagePath id}} or similar.

نصائح أخرى

I ran into a similar issue with Router and discovered it had been deprecated

For me, the resolution was to install meteorite and add Iron-Router:

mrt add iron-router

Then you can route as follows:

Router.map(function() {
     this.route('postslist', {path: '/'})
    //read the docs for your next routing needs


});

I am assuming you already have meteorite installed, if you haven't and are using uBuntu or similar flavor you can easily setup using the following:

export PATH=~/.meteor/tools/latest/bin:$PATH    //ensure you are in your project root directory

npm install -g meteorite    //must have npm installed

Figured this out from this stackoverflow link

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top