tmeasday / meteor-router

MIT License
366 stars 76 forks source link

Filter not working #69

Closed JasonMatthewsDev closed 11 years ago

JasonMatthewsDev commented 11 years ago

So just trying something similar to the examples for the filtering doesn't seem to be working

Meteor.Router.add({
    '/': 'news',
    '/forum': 'forum',
    '/news': 'news',

    '/forum/:topic/newThread': {as: 'newThread', to: function(topic){
        console.log('test');
        Session.set('forumTopic', topic);
        return 'NewThread';
    }},
    '/forum/:topic': {as: 'topic', to: function(topic){
        Session.set('forumTopic', topic);
        return 'topic';
    }},
    '/forum/:topic/:id': {as: 'thread', to: function(topic, id){
        Session.set('forumTopic', topic);
        Session.set('threadID', id);
        return 'thread';
    }}
});

Meteor.Router.filters({
    'checkLoggedIn': function(page){
        console.log('filtering');
        if (Meteor.user()){
            return page;
        }else{
            throw new Meteor.Error(403, 'Please sign in!');
            $('#loginForm').modal('show');
        }
    }
});

Meteor.Router.filter('checkLoggedIn', {only: 'newThread'});

the newThread route is called in a template event

Template.topic.events({
    'click #btn_newThead': function(e,t){
        Meteor.Router.to('newThread', Session.get('forumTopic'));
    }
});

the first console.log('test') fires when clicking the button but the second console.log('filitering') never fires.

tmeasday commented 11 years ago

It's a typo "NewThread" in your template name. Filters match on template names not route names.

JasonMatthewsDev commented 11 years ago

Thanks, I didn't realize it wasn't intended to filter route names. Thanks for the quick reply, I really like the router and transitioner.