javascript - Not found page pops up for a second - Meteor - iron - router -
javascript - Not found page pops up for a second - Meteor - iron - router -
i upgraded app meteor 1.0 , updated router.js, because can't utilize .wait() anymore. however, not found page pops second, before 'real page' shows up. how can prepare this?
here code:
this.route('gamepage', { path: '/game/:slug/', onbeforeaction: [function() { this.subscribe('singleplayer', this.params.slug); var singleplayer = this.data(); if (singleplayer) { if (singleplayer.upgrade) { this.subscribe('upgrades', this.params.slug); } } this.next(); }], data: function() { homecoming games.findone({slug: this.params.slug}); }, waiton: function() { homecoming [meteor.subscribe('singlegame', this.params.slug)]} }); any help appreciated.
try using subscriptions pattern instead.
this.route('gamepage', { path: '/game/:slug/', subscriptions: function() { homecoming meteor.subscribe('singleplayer', this.params.slug); }, onbeforeaction: function() { var singleplayer = this.data(); if (singleplayer) { if (singleplayer.upgrade) { this.subscribe('upgrades', this.params.slug); } } this.next(); }, data: function() { homecoming games.findone({slug: this.params.slug}); }, waiton: function() { homecoming [meteor.subscribe('singlegame', this.params.slug)]} }); however, of import include loading plugin take advantage of loadingtemplate.
router.configure({ loadingtemplate: 'loading' // general purpose loading template }); // built in plugin.. surprisingly not specified in current docs, can dive in code plugins. // https://github.com/eventedmind/iron-router/blob/devel/lib/plugins.js router.onbeforeaction('loading', { only: ['gamepage'] }); // show loading pages subscriptions router.map(function() { this.route('gamepage',{ //... other options here .. loadingtemplate: 'gamepageloading', // game page dedicated loading markup. }); }); there's this.ready() pattern if you'd remain @ onbeforeaction implementation.
this.route('gamepage', { path: '/game/:slug/', onbeforeaction: [function() { this.subscribe('singleplayer', this.params.slug); if(this.ready()) { var singleplayer = this.data(); if (singleplayer) { if (singleplayer.upgrade) { this.subscribe('upgrades', this.params.slug); } } this.next(); } else { this.render('loading'); } }], data: function() { homecoming games.findone({slug: this.params.slug}); }, waiton: function() { homecoming [meteor.subscribe('singlegame', this.params.slug)]} }); source: https://github.com/eventedmind/iron-router/blob/devel/guide.md#subscriptions
i think alter necessary because .wait pattern viewed unnecessary chaining , prone (coding) errors. additionally, explicitly handling .next() when overriding onbeforeaction ensures proper timing of hook (and most, if not other hooks).
javascript meteor iron-router
Comments
Post a Comment