Meteor: Collection loads when I navigate to a page, but not when URL is directly inputted

I’m a Meteor newb and would appreciate any help here.

I’m creating a flashcard app where you can create decks of cards. It saves the progress that one has made through a deck of cards.

It appears that when I navigate into a deck of cards by clicking on the name of a deck, everything works fine. But when I directly paste the URI in, the Deck collection fails to load.

The console.log in the code displays a cursor when I click. But it displays undefined when I directly enter the URI or refresh on that page, e.g. “/2gshijkhe7340vsdonj84/1”

Thanks in advance for your help!

 Router.route ('/:_id/:wordIndex', {
        template: 'wordPage',

        data: function () { 
            var index = this.params.wordIndex;
            var id = this.params._id;

            console.log(Decks);
            var word = Decks.findOne ( id, 
                        { fields: { 'wordIds': 1 } } 
                    ); 
            }
        }
    );

I tried using the waitOn function within the router already as well:

Router.configure ( {
    layoutTemplate: 'layout',
    waitOn: function () { return [
        Meteor.subscribe ('words'),
        Meteor.subscribe ('decks')
    ]}
})


Source: New Questions

Leave a Reply