使用Iron Router,"路由器未定义"

wcj*_*n11 7 meteor iron-router

我已经添加了铁路由器到我的应用程序来处理主页,关于页面和应用程序的主页面之间的路由,这是一张地图

在添加了带有陨石的铁路由器之后,我写了一个router.js文件并将其放在我的/ client文件夹中,但是我收到的错误是"未捕获的ReferenceError:未定义路由器"

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

});
});
Run Code Online (Sandbox Code Playgroud)

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

小智 6

确保你的流星版本是0.8.3或更高,并使用陨石与命令

mrt添加铁路由器

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

否则,请检查路由器配置的代码是否在Meteor.isClient范围内.如果没有,只需将它们包装在客户端范围内.

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

  Router.map(function(){
   ......
  });
}
Run Code Online (Sandbox Code Playgroud)

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

流星更新

再用陨石安装铁路由器.
如果没有出现错误消息,一切顺利