Skip to content

Instantly share code, notes, and snippets.

@djfrsn
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save djfrsn/78dcbcef77b30eabb178 to your computer and use it in GitHub Desktop.

Select an option

Save djfrsn/78dcbcef77b30eabb178 to your computer and use it in GitHub Desktop.
Router.configure({
layoutTemplate: 'Main',
loadingTemplate: 'Loading',
notFoundTemplate: 'NotFound',
load: function() {
$('html, body').animate({
scrollTop: 0
}, 400);
return $('.content').hide().fadeIn(1000);
},
waitOn: function() {
return Meteor.subscribe('recordSetThatYouNeedNoMatterWhat');
}
});
Router.map(function() {
this.route('Homepage', {
path: '/'
});
this.route('Contact', {
layoutTemplate: 'Layout',
loadingTemplate: 'Loading',
notFoundTemplate: 'NotFound',
template: 'Contact',
path: '/contact',
where: 'client',
yieldTemplates: {
'MyAsideTemplate': {
to: 'aside'
},
'MyFooter': {
to: 'footer'
}
}
});
this.route('PostShow', {
action: function() {
this.render();
this.render('templateName');
return this.render('templateName', {
to: 'region'
});
},
controller: 'CustomController',
data: function() {
return Posts.findOne(this.params._id);
},
load: function() {
return console.log('runs just once when the route is first loaded.');
},
onBeforeAction: function() {
var post;
post = this.getData();
return console.log('runs before the action function (possibly many times if reactivity is involved).');
},
onAfterAction: function() {
return console.log('runs after the action function (also reactively).');
},
path: '/posts/:_id',
unload: function() {
return console.log('runs just once when you leave the route for a new route.');
},
waitOn: function() {
return Meteor.subscribe('post', this.params._id);
}
});
this.route('TwoSegments', {
path: '/posts/:paramOne/:paramTwo'
});
this.route('Globbing', {
path: '/posts/*'
});
this.route('NamedGlobbing', {
path: '/posts/:file(*)'
});
this.route('RegularExpressions', {
path: /^\/commits\/(\d+)\.\.(\d+)/
});
return this.route('ServerRoute', {
action: function() {
var filename;
filename = this.params.filename;
this.response.writeHead(200, {
'Content-Type': 'text/html'
});
return this.response.end('hello from server');
},
where: 'server'
});
});
Router.onRun(function() {
return console.log('this happens once only when the route is loaded.');
});
Router.onData(function() {
return console.log('runs reactively whenever the data changes.');
});
Router.onBeforeAction(function() {
return console.log('runs reactively before the action.');
});
Router.onAfterAction(function() {
return console.log('runs reactively before the action.');
});
Router.onStop(function() {
return console.log('runs once when the controller is stopped, like just before a user routes away.');
});
@djfrsn
Copy link
Author

djfrsn commented Aug 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment