Limit the amount of posts displayed at once - Iron Router

When I would post every post on the server to the user it was this code,

 this.route('postsList', {
    path: '/',
    data:function(){
      Session.set('pageView','list');
      return Posts.find();
    }
  });

Now I’m learning you can limit to 5 posts loading at time. I use a Session.set to determine if to display one post or a list. How do I apply the Session.set in my postLimit route? Here is what I have so far.

Router.route('/:postsLimit?', {
name: 'postsList',
waitOn: function() {
console.log(this.params.postsLimit)
var limit = parseInt(this.params.postsLimit) || 5; 

return Meteor.subscribe('posts', {sort: {submitted: -1}, limit: limit});
 },
data: function() {

var limit = parseInt(this.params.postsLimit) || 5; 
return [
  Session.set('pageView','list'),
  posts: Posts.find({}, {sort: {submitted: -1}, limit: limit})]
 };
 }
});

Do I return with two params?

I was able to convert it to this.route syntax. No errors

 this.route('postsList', {
    path: '/:postsLimit?',
    waitOne: function() {
        var limit = parseInt(this.params.postsLimit) || 5; 
        return Meteor.subscribe('posts', {sort: {submitted: -1}, limit: limit});
    },
    data: function() {
        Session.set('pageView','list');
        var limit = parseInt(this.params.postsLimit) || 5;
        return { posts: Posts.find({}, {sort: {submitted: -1}, limit: limit}};
    }
  });

But localhost:3000/3 doesn’t work if I want to display only 3 posts.

Do you mean localhost:3000/postsList/3?

Also, setting a session variable in your data() function looks weird. Why do you need ‘pageView’?

It would be localhost:3000/3

In discover meteor, the example has it that way.

The pageView is used in this way. I have a postBlock.html that functions as showing a single post or a list, using {{#if pageView 'list}} for the post list code and {{#if pageView 'single}} for a singe post.

Part of my problem why the localhost:3000/3 isn’t working in showing just 3 posts is that accessings a user’s profile page is this format localhost:3000/userName So that could be affecting what I can’t view posting using localhost:3000/3

Hi,
Try this.
Source Code : http://meteorpad.com/pad/yz7RKzs3YfQotGBLA/PostsLimitDemo