I'm struggling to find a way to access the 'name' property of a given route. Currently I'm wanting to do this in a route, but plan on moving this code into a controller, so if its slightly different in these two instances I'd appreciate an example of both.
Basically I have the a number of routes that look like the following :
Router.route('/settings/:page?', {
name : 'settings',
controller : 'AppController',
data : function() {
return Meteor.user();
},
action : function() {
this.render('settingsHeader',{to : "contentHeader"});
if (this.params.page) {
this.render('settings'+this.params.page);
} else {
this.render('settingsbasic');
}
}
});
I'd like to get the name of the given route, so that I can replace the strings where I'm naming the route (in this case settings). Ultimately this would allow me to create a SubPageController which would neaten up my router code substantially.
This may be super simple, but I'm not finding exactly what I'm after in other SO questions or in the documentation.
Thanks in advance.
Here you have it:
iron-router > 1.0
var routeName = Router.current().route.getName();
iron-router < 1.0
var routeName = Router.current().route.name;