I have this error when running my app and attempting to route to root/about
ReferenceError: Session is not defined at [object Object].route.onBeforeAction (app/lib/routes.js:38:8) at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1) at packages/meteor/dynamics_nodejs.js:121:1 at [object Object].urlencodedParser (/home/action/.parts/packages/meteor/1.0/packages/iron_router/.1.0.7.42k4wv++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:72:36) at packages/iron:router/lib/router.js:277:1 at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) at [object Object].hookWithOptions (packages/iron:router/lib/router.js:276:1) at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)
Here is my routing code in this location lib/routes.js:
Router.map(function () {
this.route('aboutTemplate', {
name: 'aboutTemplate',
where: 'server',
path: '/about',
onBeforeAction: function(){
Session.set('active_menu_option','about');
this.next();
},
onAfterAction: function(){
},
data: function(){
return {active_menu_option: {'about':'active'}};
}
});
}
I presume the error occurs because this is now a server side route and the session object is not available outside of client scope. But is there any more information someone could give me on this?
also, while I am at it - what is the first argument representing in the above method? How is the first argument 'aboutTemplate' different from the name parameter - name: 'aboutTemplate'?
any help appreciated
Session is a client-only package, you will need a custom package (as told in the question comments) to get it on the server.
As for the first argument of Iron Router route
function, it is used to specify parameters (/posts/:id
for example) and is used by Iron Router to guess a couple parameters, such as the template to use (Router.route('homepage')
on the client will search for the homepage
template).
In that case, Iron Router will too guess the name, so your code is slightly redundant (but cleaner, in my own opinion). See more in the guide.