标签: iron-router

在活动链路的路由更改中重新运行辅助功能

我一直在使用Meteor + Iron Router来处理我正在研究的多页面应用程序,而且我已经陷入了关于命名率的辅助函数.具体来说,我一直试图让我的导航栏选项卡的活动类更新每个路由更改.

以下是我项目的相关代码:

router.js

Router.configure({
  layoutTemplate: 'mothership',
  yieldTemplates: {
  'header' : {to: 'header'},
  'footer': {to: 'footer'}
  },
});

Router.map(function () {
  // Home page
  this.route('home', {
    path: '/',
    template: 'home',
  });

  this.route('about', {
    path: '/about',
    template: 'about',
  });

  this.route('emails', {
    path: '/emails',
    template: 'emails',
  });

  this.route('people', {
    path: '/people',
    template: 'people',
  });
}); 
Run Code Online (Sandbox Code Playgroud)

mothership.html

<template name="mothership">
  <a href="#content" class="sr-only">Skip to content</a>
  <div id="wrap">
    <!-- header -->
    <div>{{yield 'header'}}</div>
    <div id="content">{{yield}}</div>
  </div>

  <div id="push"></div>
  <div id="footer">
    {{yield 'footer'}}
  </div> …
Run Code Online (Sandbox Code Playgroud)

meteor iron-router

3
推荐指数
1
解决办法
945
查看次数

没有布局模板或JSON视图的流星铁路由器

使用流星铁路由器我怎样才能呈现数据作为JSON或简单地显示它的"原始"(没有布局模板)

基本上我希望能够做到这样的事情:

this.route('rawdata', {
  path: '/raw/:collection',
  layoutTemplate: 'nolayout',
  template: 'raw'
})
Run Code Online (Sandbox Code Playgroud)

where / raw/posts将显示Posts(集合)的原始json.

谢谢!

备注:

我知道Meteor中JSON端点 但是流星路由器已经停止,而Iron-Router似乎没有JSON端点功能.

我也看了一下https://atmospherejs.com/package/collection-api,但它不适合我的需要,因为我需要能够选择集合/记录的字段子集.

json meteor iron-router

3
推荐指数
1
解决办法
2069
查看次数

具有多个参数的铁路由器嵌套路由

我有两个型号:sitesarticles.每个站点可以有多个文章.我想在这条路线中查看这篇文章:/siteName/articleFriendlyTitleUrl.目前我有帮助方法来制作这样友好的网址:

getFriendlyUrl = function(urlString){
  urlString = urlString.toLowerCase();
  urlString = str.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-');
  return urlString;
}
Run Code Online (Sandbox Code Playgroud)

我的router.js档案:

this.route('showArticle', {
  path: '/article/:title'),
  layoutTemplate: 'artLayout',
  data: function(){
  viewData = {
    title: Articles.findOne({title: this.params.title}),
    site:  Sites.findOne({name: this.name})
  }
  return viewData;
});
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何实现这个?我也试过这个路径:

/:siteName/:articleId
Run Code Online (Sandbox Code Playgroud)

但没有成功 - 任何建议?

routing meteor iron-router

3
推荐指数
1
解决办法
2056
查看次数

Meteor:模板用数据渲染后的调用函数

我想在旋转木马里面显示一些帖子.对于旋转木马,我使用OwlCarousel.

    <div class="owl-carousel" id="featured-carousel">
        {{#each featuredPosts}}
        <div>
            <h2>
                {{postTitle}}
            </h2>
        </div>
        {{/each}}
    </div>
Run Code Online (Sandbox Code Playgroud)

我这样叫我的旋转木马:

Template.featuredCarousel.rendered = function(){
$('#featured-carousel').owlCarousel({
    loop:true,
    autoplay:true,
    autoplayTimeout:3000,
    items:1,
    smartSpeed:1080,
    padding:80
});
this.rendered = true;
};
Run Code Online (Sandbox Code Playgroud)

我得到的结果是Owl基本上认为我只有一个项目要在转盘中显示多个div.显然,在模板的#each-part完成之前或数据到达之前调用Template.featuredCarousel.rendered中的函数.

如何在完全呈现模板(包括所有数据)后调用实例化轮播的功能?

非常感谢您的帮助.

PS:我使用铁路由器进行路由,如下所示:

Router.map(function(){
this.route('home', {
    path: '/',
    waitOn: function(){
        return Meteor.subscribe('featured');
    },
    data: function(){
        return {featuredPosts: Featured.find({})};
    }
});
});
Run Code Online (Sandbox Code Playgroud)

PPS:我也尝试过使用加载模板,但这也无济于事.

templates meteor iron-router meteor-blaze owl-carousel

3
推荐指数
1
解决办法
4269
查看次数

Meteor.Router与铁路由器

我想创建一个多页Meteor网站和移动应用程序.因此,我正在寻找路由服务.

研究,我收集铁路由器是我正在寻找的.但许多教程也提到了Meteor.Router

Iron Router和`Meteor.Router`之间有什么区别(如果有的话)?

routing meteor iron-router

3
推荐指数
1
解决办法
891
查看次数

流星铁路由器并获取帐户入口包的所有路由的名称

流行的帐户入口包中有一个与铁路由器相关的错误.我相信铁路由器的后期版本改为更好地作为中间件工作,因此呼吁Router.routes

在该文件的第87行,使用以下代码:

_.each Router.routes, (route)->
  exclusions.push route.name
# Change the fromWhere session variable when you leave a path
Router.onStop ->
  # If the route is an entry route, no need to save it
  if (!_.contains(exclusions, Router.current().route?.getName()))
    Session.set('fromWhere', Router.current().path)
Run Code Online (Sandbox Code Playgroud)

不幸的是,似乎没有在Router.rou上做一个_.each是一个解决方案,因为Router.routes不会返回并且对象中包含.name属性.

你如何获得最新铁路由器的所有路线的名称?

routing middleware meteor iron-router

3
推荐指数
1
解决办法
1133
查看次数

Meteor:如何发布自定义JSON数据?

编辑:我使用的解决方案是@Kyll的解决方案.

假设我想要返回的服务器端对象"构建起来很复杂",需要来自不同集合的不同属性.

我第一次尝试:
/server/publications.js

Meteor.publish('myCustomDocument', function(){
    // suppose here that I need to X.find() different collections
    // and create a complex Array of JSON data (which contains different
    // attributes from different Collections
    return [
            {appName: 'aName',
             category: 'catName',
             anotherField: 'something'},
            (...)
        ];
});
Run Code Online (Sandbox Code Playgroud)

它不起作用,因为它没有返回游标.我想要做的是创建一个从不同集合构建的文档(或文档数组).
我不需要观察该文档的更改.

我为它创建了一个集合:

/collections/myCollection.js

MyCollection = new Meteor.Collection('myCollection');
Run Code Online (Sandbox Code Playgroud)

在客户端,使用铁路由器,我试图做的是:

/lib/router.js

this.route('myPage',{
    path: '/myPage',
    waitOn: function(){ return Meteor.subscribe('myCollection'); },
    data: function(){ return MyCollection.find(); }
});
Run Code Online (Sandbox Code Playgroud)

如何实现向客户端发送非活动数据?

meteor iron-router

3
推荐指数
2
解决办法
1881
查看次数

流星与铁路由器不能得到光滑的旋转木马工作

我正在使用铁路由器,我有一个路线"模型",其中有一个项目列表.当用户单击其中一个项目时,将使用新的路径"模型",所选项目的名称将作为参数传递,并用于从数据库加载有关该模型的数据.

我想使用光滑的轮播,使用从数据库返回的图像数组(基于参数).

<div id="carousel">
    {{#each images}}
    <div class="item">
        <img src="/images/{{this}}" alt="">
    </div>
    {{/each}}
</div>
Run Code Online (Sandbox Code Playgroud)

我应该在哪里调用光滑的init?

meteor iron-router slick.js

3
推荐指数
1
解决办法
690
查看次数

在Meteor中配置铁路由器 - React

使用Meteor 1.2.0.1和React.我的简单app很棒,但现在我需要铁路由器.

应用布局:

client\
  app.jsx
lib\
  router.jsx
server
views\
  home.jsx
  layout.jsx
Run Code Online (Sandbox Code Playgroud)

home.jsx:

Home = React.createClass({
  render() {
    return (
      <div>
        <h3>Hello World</h3>
        <p>from home</p>
      </div>
    );
  }
});
Run Code Online (Sandbox Code Playgroud)

layout.jsx:

Layout = React.createClass({
  render() {
    return (
      <div>
        {this.props.children}
      </div>
    );
  }
});
Run Code Online (Sandbox Code Playgroud)

routes.jsx:

Router.route('/', () => {
  let page = (
    <Layout>
      <Home/>
    </Layout>
  );
  React.render(page, document.body);
});
Run Code Online (Sandbox Code Playgroud)

当然,在我的app.jsx工作中,它可以很好地显示在html的主体上,但是设置不适用于多页应用程序,因此需要路由.里面是:

Meteor.startup(() => {
  let app = (
    <Layout>
      <Home/>
    </Layout>
  );
  React.render(app, document.body);
});
Run Code Online (Sandbox Code Playgroud)

问题是,如何让铁路由器(routes.jsx)显示内容?

meteor reactjs iron-router

3
推荐指数
1
解决办法
2586
查看次数

更新到Meteor 1.3后出错 - 名称为"onBeforeAction"的处理程序已存在

我的应用程序一直在工作,直到我将其更新为Meteor 1.3.现在我收到这个错误:

Exception in callback of async function: Error: Handler with name 'onBeforeAction' already exists.
at MiddlewareStack._create (http://localhost:3000/packages/iron_middleware-stack.js?hash=8a2aa73e86a32698fb9f60cea452e0ecb2e72b7f:190:13)
at MiddlewareStack.push (http://localhost:3000/packages/iron_middleware-stack.js?hash=8a2aa73e86a32698fb9f60cea452e0ecb2e72b7f:206:22)
at http://localhost:3000/packages/iron_middleware-stack.js?hash=8a2aa73e86a32698fb9f60cea452e0ecb2e72b7f:224:12
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=8de51f9d86e95ae2ffee15a8db324a1decccba3e:139:11)
at MiddlewareStack.append (http://localhost:3000/packages/iron_middleware-stack.js?hash=8a2aa73e86a32698fb9f60cea452e0ecb2e72b7f:220:5)
at http://localhost:3000/packages/iron_middleware-stack.js?hash=8a2aa73e86a32698fb9f60cea452e0ecb2e72b7f:226:19
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=8de51f9d86e95ae2ffee15a8db324a1decccba3e:139:11)
at MiddlewareStack.append (http://localhost:3000/packages/iron_middleware-stack.js?hash=8a2aa73e86a32698fb9f60cea452e0ecb2e72b7f:220:5)
Run Code Online (Sandbox Code Playgroud)

我使用的唯一地方onBeforeAction是我的铁路由器路由控制器.它们都在同一个router.js文件中.

我定义了几个路由控制器,首先ApplicationController是扩展RouteController,然后是各种扩展的控制器ApplicationController.

ApplicationController = RouteController.extend({
  onBeforeAction: function() {
    //some code
    this.next();
  }
});

SomeController = ApplicationController.extend({
  onBeforeAction: function() {
    //some code
    this.next();
  }
});
Run Code Online (Sandbox Code Playgroud)

从错误消息我无法找出错误或在哪里寻找问题.

错误消息中提到的包的版本是:

iron:router@1.0.12 …
Run Code Online (Sandbox Code Playgroud)

updates meteor iron-router

3
推荐指数
1
解决办法
774
查看次数