Search code examples
meteoriron-router

Iron router Couldn’t find a template named... Are you sure you defined it?


I am trying to render a template on a given page but I get the following error:

Couldn't find a template named "adPage" or "adPage". Are you sure you defined it?

myapp/lib/router.js

This is how I defined the route:

Router.route("/dashboard/adpage/:_id", {
   // name:"adPage",
   template:"adPage",

   data:function(){
     return Ads.findOne({_id: this.params._id});
   },
   onBeforeAction : function()
   {
     if(Meteor.userId())
     {
       //user is loggedin continue the route
       this.next();
     }
     else {
       console.log("user not loggin, redirect to login page");
       this.render('login');
     }
   },
   onAfterAction: function(){
     document.title = 'Annonce';
   },
   waitOn:function(){
      return Meteor.subscribe("adDetails",this.params._id);
   }
 });

myapp/client/main.html

<template name="main">
...
  {{> yield}}
...
</template>

myapp/client/adPage/adPage.html

<template name="adPage">
   {{title}}
...
</template>

myapp/client/adPage/adPage.js

Template.adPage.onCreated(function() {
  console.log("on created");
});

If I move the adPage template to my main.html file, I no longer have the error (I can see the title) but the onCreated is not called.

I tried to put everything in the same client folder and renaming adPage.js to _adPage.js and everything worked as expected. So I suspect something wrong with the load order but can't figure out what...

Thanks !


Solution

  • If you are using an adblocker. Try to disable it. Its probably because of the filename