我已经在我的应用程序中添加了 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/