meteor - 使用 Iron Router, "Router is not defined"

标签 meteor iron-router

我已经在我的应用程序中添加了 Iron-router 来处理主页、关于页面和应用程序主页( map )之间的路由

用陨石加铁路由器后,
我写了一个 router.js 文件并将它放在我的/client 文件夹中,但是我收到一个错误消息“Uncaught ReferenceError: Router is not defined”

我用 chrome devtools 检查了错误,它指向我在下面添加的 router.js 开头的“Router.configure(...”

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');
    }

});
});

有谁知道为什么我收到未定义路由器的错误?

最佳答案

确保您的 meteor 版本是 0.8.3 或 up 并通过命令使用陨石

mrt add iron-router



其他人会导致铁路由器构建错误。

否则,请检查您的路由器配置代码是否在 Meteor.isClient 范围内。
如果没有,只需将它们包装在客户端范围内。
if(Meteor.isClient){
  Router.configure({
   ......
  });

  Router.map(function(){
   ......
  });
}

如果 Iron-Router 安装在 0.8.3 以下版本,你应该从包和 smart.json 中删除它们,
用命令更新 meteor ,

meteor update



并用陨石再次安装铁路由器。
如果没有出现错误信息,则一切顺利

关于meteor - 使用 Iron Router, "Router is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21296078/

相关文章:

javascript - 在浏览器上刷新集合

javascript - ".."在 Meteor Spacebars 语句中做什么?

javascript - Meteor:在发布中使用 Meteor._sleepForMs() 时 Iron router 不显示加载模板

javascript - 将 div 链接到路由 meteor (Iron Router)

javascript - 参数 'HomeCtrl' 不是函数,在使用 Meteor-Up 部署后未定义

javascript - Meteor.js 重用具有不同数据的模板

CSS/少 : apply attribute globally at once for specific tag (ex> <a> tag)

javascript - 在 Meteor.js 中基于 URL 发布集合

javascript - 有没有办法重新加载{{>yield}}的主模板

javascript - 使用iron-router版本1.0.0-pre2下载文件链接