0

I am using iron:router@1.0.0-pre3 with meteor 9.3.1.

I am creating a smart package. I want to define routes inside the smart package and not in the main app.js file.

I tried adding following code in the .js file for smart-package:

Router.route('/path', function () {
  this.render('someTemplate');
});

The above code gives a "Router not defined" error. Don't know what should be added to "api.use" in "Package.onUse(function(api)" for Iron:Router in the "package.js" file.

Is it possible to define routes inside smart-package? How can I do this?

Update:

After adding iron:router to api.use the "Router not defined" error is gone.

However, the route is still not working. I have added the route in mypack.js. mypack.js is only available to client.

Package.onUse(function(api) {
  api.versionsFrom('METEOR@0.9.3.1');
  api.use(['iron:router', 'templating'], 'client');
  api.addFiles(['mypack.js', 'mypack.html'], 'client');
});
Anish Singh
  • 881
  • 1
  • 13
  • 33
  • you should edit this to include the link to github where it explains why it's not working – B M May 02 '15 at 11:10

1 Answers1

2

Yes, you need to define a dependency on the iron router package in your package. In package.js, in the call to api.onUse, just add api.use('iron:router').

Peppe L-G
  • 7,351
  • 2
  • 25
  • 50
  • Thanks! "Router not defined" error is now gone. I have updated the question. Don't know how to declare routes inside js file that is only available to client. – Anish Singh Oct 06 '14 at 19:16
  • @AnishSingh, you should be able to use it as usual, for example: `Router.route('/home', {name: 'home', template: 'home'})`. – Peppe L-G Oct 06 '14 at 19:58
  • sadly it's not working. In fact, if I place `Router.route('/', function() { this.render('hello'); });` inside `if (Meteor.isClient)` in the main app.js file, the route stops working even without smart-package coming into picture. – Anish Singh Oct 07 '14 at 02:47
  • Oups, I may have been miss leading you a bit. `api.use('iron:router')` will add the latest stable version of iron router (9.4 at the moment, I think). Which version do you use in your app? In 9.4, the route should look like this instead: `Router.map(function(){ this.route('home', {path: '/home', template: 'home'}) })`. – Peppe L-G Oct 07 '14 at 06:41
  • iron:router version is 1.0.0-pre3. Seems like adding a route from inside a smart-package is not possible. Refs: https://github.com/EventedMind/iron-router/issues/897 – Anish Singh Oct 07 '14 at 17:49