Skip to content

Instantly share code, notes, and snippets.

@sferoze
Created June 5, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferoze/3e03d16103d039fa3a6b to your computer and use it in GitHub Desktop.
Save sferoze/3e03d16103d039fa3a6b to your computer and use it in GitHub Desktop.
Meteor Router example
Router.configure
layoutTemplate: 'layout',
progressDelay : 100
loadingTemplate: 'loading'
waitOn: ->
if Meteor.user()?
[
#Meteor.subscribe 'notifications'
Meteor.subscribe 'myFamilies'
]
#Do not require login for all public routes
#Router.onBeforeAction 'loading'
Router.map ->
@route 'landingPage',
path: '/',
progress: false
@route 'login',
path: '/login'
# @route 'signup',
# path: '/signup'
# onBeforeAction: ->
# Session.set 'inviteToken', ''
# @next()
@route 'signup',
template: 'signup'
path: '/signup/:token?'
onBeforeAction: ->
if @params.token?
Session.set 'inviteToken', @params.token
@next()
onAfterAction: ->
if Meteor.userId()?
Meteor.setTimeout ->
Bert.alert 'Please sign out before signing up for a new account!'
, 300
@route 'forgotPassword',
path: '/forgotpassword'
@route 'dashboard',
path: '/dashboard'
# waitOn: ->
# if Meteor.userId()?
# Meteor.subscribe 'mySets'
@route 'setup',
path: '/setup',
progress: false
@route 'setupNewFamily',
path: '/setup/newfamily/:_id'
subscriptions: ->
Meteor.subscribe 'invites', @params._id
onBeforeAction: ->
Session.set 'familyId', @params._id
@next()
data: ->
data =
familyId: @params._id
@route 'familyDashboard',
path: '/family/:_id?',
# subscribe: ->
# [
# Meteor.subscribe 'myFamily'
# ]
onBeforeAction: ->
if not @params._id?
if Meteor.user().lastFamilyId?
family = Families.findOne
_id: Meteor.user().lastFamilyId
else
family = Families.findOne()
if not family?
Router.go 'setup'
else
Router.go 'familyDashboard', {_id: family._id}
@next()
data: ->
familyId = @params._id
family = Families.findOne
_id: familyId
return null unless family?
Session.set 'familyId', family._id
data =
family: family
@route 'settings',
path: '/family/:_id/settings'
data: ->
familyId = @params._id
family = Families.findOne
_id: familyId
data =
family: family
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment