Iron Router inside package: cannot find template

2019-09-08 14:59发布

问题:

I am using Iron Router inside a package, and it complains that it cannot find a template, even though I have defined it.

I have defined a template called layout inside my package: client/templates/shared/layout.html

And I have required that file in package.js like this:

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');

  api.use('iron:router@1.0.9');

  api.addFiles([
    'both/routes.js'
  ], ['client', 'server']);

  api.addFiles([
    'client/templates/shared/layout.html',
    'client/templates/home.html'
  ], 'client');
});

And I am using layout template in my route definition file, both/routes.js

Router.configure({
  layoutTemplate: 'layout'
});

Router.route('/', {
  name: 'home',
  template: 'home'
});

And in my main app, I am using this package. It can be found at .meteor/packages.

But when I navigate to /, I get

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

I tried to restart the server without success. What am I missing?

回答1:

You might also need the following two:

api.use(['templating'], 'client'); // The templating package

api.export('layout' ['client', 'server']); // Export your template.