Using Iron Router, "Router Undefined"

I added an iron router to my application to handle the routing between the home page, the page and the main page of the application, which is a map

After adding an iron router with a meteorite, I wrote a router.js file and placed it in the “My Client” folder, however I get the error message “Uncaught ReferenceError: Undefined”

I checked the error with chrome devtools and pointed to "Router.configure (..." at the beginning of router.js, which I added below

Router.configure({ layoutTemplate: 'layout', loadingTemplate: 'loading' }); Router.map( function () { //the about route this.route('about', { path: '/about', template: 'about', action: function () { console.log('now routing the about template'); } }); this.route('home', { path: '/', template: 'home', action: function () { console.log('now routing the home template'); } }); //the map route this.route('map', { path: '/map', template: 'map', action: function () { console.log('now routing the map template'); } }); }); 

Does anyone know why I am getting the error that the router is not defined?

+7
meteor iron-router
source share
4 answers

Make sure your meteor version is 0.8.3 or up and use a meteorite with the command

mrt add an iron router

Others will cause errors in building an iron router.

Otherwise, verify that your router configuration codes are in the Meteor.isClient area. If not, just wrap them in a client scope.

 if(Meteor.isClient){ Router.configure({ ...... }); Router.map(function(){ ...... }); } 

If Iron-Router was installed below version 0.8.3, you must remove them from the packages and smart.json, update the meteorite using the command,

Meteor update

and install the iron meteorite router again.
If error messages do not appear, everything goes well.

+6
source share

I had similar problems with adding an iron router in Meteor 0.8.3.

This recipe seems to work for me.

  • Add an iron router to smart.json (or create a new project):

{"packages": {"iron-router": {"version": "0.8.2"}}}

  • Meteor update

At this point, the iron router is in the packages folder, but cannot be listed in the .meteor / packages list. If not:

  • Meteorite add an iron router

Hope this will be helpful

+2
source share

I understand that you fixed this, but for documentation purposes:

Including Iron Router in the lib / directory will allow the client and server to access the code and download it first.

See What are the best practices for structuring a large Meteor application with many HTML template files?

+1
source share

It is possible that iron-router installed correctly, but is not configured to use. It just happened to me, and I used your question to understand a little more of my problem.

Actually, I had a package present in package and in smart.json/lock , but it was not used in the .meteor/packages file and was not loaded when the meteor started. So he could not find him. Just adding the package name, fixed it.

0
source share

All Articles