Meteor 铁制路由器';找不到名为“的模板”;“布局”;或;“布局”;

Meteor 铁制路由器';找不到名为“的模板”;“布局”;或;“布局”;,meteor,meteor-blaze,Meteor,Meteor Blaze,在转换到Meteor的新文件结构后,一整天都有奇怪的错误。铁路由器似乎坏了 我有layout.html和js文件。名称也用小写字母表示 完整错误: Router.configure({ layoutTemplate : 'layout', loadingTemplate : 'loading', notFoundTemplate : 'notFound', waitOn: function() { return [ Meteor.

在转换到Meteor的新文件结构后,一整天都有奇怪的错误。铁路由器似乎坏了

我有layout.html和js文件。名称也用小写字母表示

完整错误:

Router.configure({
   layoutTemplate    : 'layout',
   loadingTemplate   : 'loading',
   notFoundTemplate  : 'notFound',
   waitOn: function() {
      return [
         Meteor.subscribe('allUsers'),
         Meteor.subscribe('otherUser')
      ];
   }
});

Router.route('/',{ 
  name: 'home',
   onBeforeAction: function () {
      if( Meteor.userId() ){ 
         Router.go('/new'); 
      } else {
         this.next();
      }
   }
});
找不到名为“布局”或“布局”的模板。你确定你 定义它

我的文件是:

Router.configure({
   layoutTemplate    : 'layout',
   loadingTemplate   : 'loading',
   notFoundTemplate  : 'notFound',
   waitOn: function() {
      return [
         Meteor.subscribe('allUsers'),
         Meteor.subscribe('otherUser')
      ];
   }
});

Router.route('/',{ 
  name: 'home',
   onBeforeAction: function () {
      if( Meteor.userId() ){ 
         Router.go('/new'); 
      } else {
         this.next();
      }
   }
});
  • client/main.html和main.js-->
    在这里定义

  • 导入/ui/layouts-->包含layout.html和layout.js
    在这里定义

  • 导入/启动/两个-->包含 路由器.js
路由器文件:

Router.configure({
   layoutTemplate    : 'layout',
   loadingTemplate   : 'loading',
   notFoundTemplate  : 'notFound',
   waitOn: function() {
      return [
         Meteor.subscribe('allUsers'),
         Meteor.subscribe('otherUser')
      ];
   }
});

Router.route('/',{ 
  name: 'home',
   onBeforeAction: function () {
      if( Meteor.userId() ){ 
         Router.go('/new'); 
      } else {
         this.next();
      }
   }
});
当i console.log
typeof(Template.layout)
时,它返回undefined

因此,当我将
layout.html
layout.js
main.html
一起移动到客户端文件夹时,错误消失了,但仍然显示空白页面,但给出了一个错误,即缺少名为“设置”的页面(但是settings.html和js文件都存在于
import/ui/pages
中。但是上面的console.log返回了一个对象。奇怪

PS:在侧注上

我在服务器文件夹的main.js文件中尝试了
import'/imports/startup/client';
,以使上面的htmls正常工作。我得到了
'Error:not find module'/imports/startup/client'
。所以我只是先对其进行注释,以解决上述问题

我还在client main.js中添加了
import'../imports/ui/layouts/layout.html';
import'../imports/ui/pages';
。但错误是
找不到模块'../imports/ui/pages'
,系统仍然看不到设置


有人能解释一下吗?谢谢!

把你的blaze html文件放在
/client
-html文件不能按原样导入。你的js文件可以迁移到
imports
目录结构,但你必须从每个文件导出函数,然后在需要的地方导入它们。我个人不确定将blaze项目迁移到新结构是值得的,如果您使用react,它会更有用。

这是我在路由器文件中使用我的项目的方式:

import '../../ui/layouts/mainlayout.js';
您不必将html文件放在客户端文件夹中。我将我的html文件放在imports中,并使用一个通用页面在page.js中执行此操作:


import./page.html
然后是我的其余代码。

在给出的示例中,Meteor提到的导入有启动,ui…其中ui有单独的页面。因此,这纯粹是针对js和jsx的?按客户机…它是仅限于客户机主文件夹还是也导入/startup/client?在react中,只有真正的js/jsx和css文件,这两个文件都可以导入的.html文件并未真正使用。
/client
或其子目录下的文件会自动缩小、绑定并发送到客户端,但除非导入,
导入
下的任何文件都不会发送到客户端。通常,
/client/main.js
会执行第一次导入然后它导入的文件导入其他文件,依此类推。