简体   繁体   English

流星铁路由器没有加载模板

[英]Meteor Iron Router not loading template

I am trying to load templates using iron router and none of the templates for the routes load. 我正在尝试使用铁路由器加载模板,并且没有用于路由加载的模板。 The url will change when the items are clicked but the current page never changes. 单击项目时,URL将更改,但当前页面永远不会更改。

Lib/router.js - Lib / router.js -

Router.configure({
  // we use the  appBody template to define the layout for the entire app
  layoutTemplate: 'appBody',

  // the appNotFound template is used for unknown routes and missing lists
  notFoundTemplate: 'appNotFound',

  // show the appLoading template whilst the subscriptions below load their data
  loadingTemplate: 'appLoading',

  // wait on the following subscriptions before rendering the page to ensure
  // the data it's expecting is present
  waitOn: function() {
    return [
      Meteor.subscribe('users'),
      Meteor.subscribe('roles')
    ];
  }
});

dataReadyHold = null;

if (Meteor.isClient) {
  // Show the loading screen on desktop
  Router.onBeforeAction('loading', {except: ['join', 'signin']});
  Router.onBeforeAction('dataNotFound', {except: ['join', 'signin']});

}

Router.map(function () {
  Router.route('home', {
    path: '/',
    onBeforeAction: function() {
      this.next();
    },
    action: function() {
      this.render('home');
    }
  });
  Router.route('adminPanel', {
    path: 'adminPanel',
    onBeforeAction: function() {
      this.next();
    },
    action: function() {
      console.log("hit admin");
      this.render('adminPanel');
    }
  });

});

The two links: 这两个链接:

            <li>
                <a href="/"><i class="fa fa-home"> Home</i></a>
            </li>
            <li>
                <a href="/adminPanel"><i class="fa fa-users"> Administration Panel</i></a>
            </li>

The 'home' template is very basic: 'home'模板非常基本:

<template name="home">
<h1>Welcome </h1>
<h2>Site in development</h2>
</template>

The 'adminPanel' template: 'adminPanel'模板:

<template name="adminPanel">
  <h1><i class="fa fa-users"> Administration Panel</i></h1>
    {{> addUserModal}}
    {{> tabular id="userTable" table=TabTables.Users class="table table-striped table-bordered table-condensed"}}
    {{> addRoleModal}}
    {{> tabular id="userTable" table=TabTables.Roles class="table table-striped table-bordered table-condensed" }}
    {{> autoformModals}}
</template>

Here is the file structure if it helps: 如果它有帮助,这是文件结构:

.
├── client
│   ├── head.html
│   ├── routers
│   └── templates
│       ├── adminPanel.css
│       ├── adminPanel.html
│       ├── adminPanel.js
│       ├── app-not-found.html
│       ├── app-not-found.import.less
│       ├── appBody.html
│       ├── home.html
│       ├── loading.html
│       └── loading.import.less
├── lib
│   └── router.js
├── public
│   └── images
└── server
    └── publish.js

Your call to the Router.map function is unnecessary. 您不需要调用Router.map函数。 It doesn't do much, as you can see here . 它没有太大作用,你可以在这里看到。

Also you can omit the onBeforeAction hook if you're just calling this.next() . 如果您只是调用this.next()也可以省略onBeforeAction挂钩。

But I too, don't see anything wrong with your code. 但我也是,你的代码看不出任何问题。 Here are some things you could try tho: 以下是您可以尝试的一些事情:

  • Check if your subscriptions are working properly 检查您的subscriptions是否正常运行
  • Make sure your calling > yield in your layout 确保您的布局中的调用> yield
  • Check for errors in your appLoading template 检查appLoading模板中的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM