如何在不更改路径的情况下激活铁路由器路由? [英] How do I activate an Iron Router route without changing the path?

查看:146
本文介绍了如何在不更改路径的情况下激活铁路由器路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Meteor应用程序,我试图传递数据从我的铁路由器控制器到一个模板,在我的应用程序的一部分。如何在不更改路径的情况下激活路由?我不想切换页面,只渲染部分与我的数据(如果这是有道理的)。

In my Meteor app, I'm trying to pass data from my Iron Router controller to a template that's a partial in my app. How do I activate a route without changing the path? I don't want to switch pages, only render the partial with my data (if that makes sense).

以下是应用程式的工作原理:

Here's how the app works:

现在,当我按一下下拉式连结my navbar

Right now, the route is activated when I click a dropdown link in my navbar

Template.navbar.events
  'click #threads-link': (event)->
    Router.go 'allThreads'

这会使模板与我的数据一样长在我的路线有一条路径。但由于我不想改变路径,我试图离开路径 - 然后模板不从我的控制器检索数据!

This renders the template with my data as long as I have a path in my route. But since I don't want the path to change, I tried leaving the path--and then the template doesn't retrieve the data from my controller!

Router.map ->
  @route "allThreads",
    controller: ThreadsController 

让我的模板部分访问控制器中的数据,而不改变路径?提前感谢!

Do you know how to get my template partial to access the data in the controller without changing the path? Thanks in advance!

推荐答案

首先,您可能会看到一些问题,因为最新版本的Iron Router要求您Meteor v0.8.0。如果你使用的是以前版本的Meteor,你需要使用旧版的Iron Router(0.6)。

First, you're probably seeing some issues because the latest version of Iron Router requires you to be on Meteor v0.8.0. If you're on a previous version of Meteor you'll need to use the older Iron Router (0.6).

要自定义ThreadsController的渲染, action函数,或者你可以定义一个钩子。然后,您可以调用render方法来呈现您想要的任何模板。下面是一个例子:

To customize rendering inside of your ThreadsController you can just override the action function, or you can define a hook. Then, you can call the render method to render whichever templates you'd like. Here is an example:

ThreadsController = RouteController.extend({
  action: function () {
    // Example 1. render this controller's default template and all yields
    this.render();

    // Example 2. render myTemplate into the main yield
    this.render('myTemplate');

    // Example 3. render templates into yield regions
    this.render('myFooter', {to: 'footer'});
  }
}); 

这篇关于如何在不更改路径的情况下激活铁路由器路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆