Search code examples
meteoriron-router

MeteorJS Iron Router - Is it possible to have the router controller in a separate JS file?


Is there is a way to have the router controller in a different file, my router is getting pretty big and would like to spit the code up a bit.


Solution

  • Sure, just organize your code base as follow :

    lib/router.js

    Router.route("/",{
      name:"home",
      controller:"HomeController"
    });
    
    Router.route("/about",{
      name:"about",
      controller:"AboutController"
    });
    

    lib/controllers/home.js

    HomeController=RouteController.extend({
      template:"home",
      onBeforeAction:function(){
        //
        this.next();
      },
      data:function(){
        return {
          //
        };
      }
    });
    

    lib/controllers/about.js

    AboutController=RouteController.extend({
      template:"about",
      //
    });
    

    And so on...