Search code examples
meteoriron-router

Variable name in iron router


I want to assign a variable to a route's name property in an iron router route in my meteor application but whenever I try to do so the application crashes.

Router.route('/:tpl', function(){
    this.render(this.params.tpl)
}, {
    name:variableName // I tried name:this.params.tpl also
});

The main purpose of this is to set the document title of the page on the basis of the route name by below code

Router.onAfterAction(function() {
    document.title = Router.current().route.getName();
});

Whenever I set the route name to a string the code works but when I assign a variable to route name then the code breaks.

Note - I'm using the latest version of Meteor and Iron Router.


Solution

  • You can't have a variable route name. The route name is used by iron router to identify the route, think of it like the route's ID.

    What you could do for your purpose, as you apparently want to have the template name in the title:

    Router.onAfterAction(function() {
        document.title = this.params.tpl;
    });