Last active
August 29, 2015 14:26
-
-
Save djfrsn/78dcbcef77b30eabb178 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.'); | |
| }); | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit : https://gist.github.com/LeCoupa/59738c28fdc9085b9212