【问题标题】:Iron Router: No route definitions foundIron Router:找不到路由定义
【发布时间】:2018-11-21 19:02:47
【问题描述】:

我正在开发一个基本的 meteorjs 应用程序,并使用 Iron 路由器进行客户端路由。我设置了我的路线、出版物和模式,但我无法让 Iron 路由器运行。在我启动我的应用程序后,它总是向我显示“未找到路由定义”。我的 router.js 在 /lib 中。改变它的位置根本不起作用。我没有任何控制台日志。任何帮助表示赞赏。

我的 router.js:

Router.route('/', {
  name: 'main',
  layoutTemplate: 'mainLay',
  waitOn: function() {
    return Meteor.subscribe('posts');
 },
  action: function() {
    this.render('allPosts');
}
 });

 Router.route('/create-post', {
  name: 'createPost',
  layoutTemplate: 'mainLay',
  action: function() {
    if (Meteor.userId()) {
      this.render('createPost');
    }
    else {
    Router.go('/');
   }
  }
 });

Router.route('/post/:postId', {
 name: 'post',
 layoutTemplate: 'mainLay',
 waitOn: function() {
  return [
    Meteor.subscribe('comments', this.params.postId),
    Meteor.subscribe('post', this.params.postId)
  ];
},
action: function() {
  var postId = this.params.postId;
  this.render('postDetail');
}
});

在我的 .meteor/packages 我有条目:

iron:router

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    如果您不清楚应用程序结构,这可能会有所帮助: https://guide.meteor.com/structure.html#example-app-structure

    找不到 iron-router 的模板:

    客户端入口点不知道 router.js:/client/main.js

    client/
      main.js                      # client entry point, imports all client code
    

    在你目前的情况下:

    在 main.js 中检查是否添加:

    导入'/lib/router.js';

    【讨论】:

    • import '/lib/router.js'; 是最重要的事情之一,如果忽略它可能会导致不眠之夜。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 2015-02-12
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多