标签: iron-router

铁路由器中的多个订阅

我一直在使用评论功能处理应用程序.这导致必须订阅发表评论的集合和评论集合本身.现在它看起来像这样:

<template name="bookView"> {{> book}} {{> comments}} </template>

this.route('book', {
    path: '/book/:_id',
    template: 'bookView',
    waitOn: function() { return Meteor.subscribe('book');},
    action: function () {
        if (this.ready()){
            this.render();
        }
        else
            this.render('loadingTemplate');
    },
    data: function() {return Books.findOne(this.params._id);}
});
Run Code Online (Sandbox Code Playgroud)

但是现在我想加载属于那本书的所有评论.或者我应该在Template.comments.rendered中处理评论的订阅?

javascript meteor iron-router

10
推荐指数
2
解决办法
4612
查看次数

铁路由器waitOn Meteor.user()

我会在数据铁路由器中使用Meteor.user(),但这在开始时是未定义的...

我正在尝试:

waitOn: function() {
   return curretUserHandle;
},
data: function() {
   // access to Meteor.user().username, give me undefined

[...]

var curretUserHandle = {
    ready: function () {
        return 'undefined' !== typeof Meteor.user();
    }
};
Run Code Online (Sandbox Code Playgroud)

但是,在curretUserHandle.ready()返回true之前,始终会调用route的数据函数

我知道我可以在数据中添加if(Meteor.user()),但是这个选项不喜欢.

为什么数据不等待Meteor.user()准备好了?

javascript meteor iron-router

10
推荐指数
1
解决办法
1829
查看次数

使用铁路由器中的Router.go传递查询参数

我试图在Router.go中传递查询参数,如下所示:

var filter = 'abc';
var path = Router.current() && Router.current().path;
Router.go(path, {query: {filter: filter}});
Run Code Online (Sandbox Code Playgroud)

但是这并没有改变url,它仍然只加载当前路径而没有查询字符串.但是,如果我手动将查询参数添加到路径,如:

Router.go(path+'?filter='+filter);
Run Code Online (Sandbox Code Playgroud)

这很好用.但是因为我试图用一些过滤的数据加载相同的页面.因此,单击过滤器按钮会反复将过滤器字符串反复附加到路径.

使用铁路由器传递查询字符串的正确方法是什么?

meteor iron-router

10
推荐指数
2
解决办法
1万
查看次数

Meteor中服务器端路由的身份验证

为服务器端路由验证用户的最佳方法(最安全和最简单)是什么?

软件/版本

我正在使用最新的Iron Router 1.*和Meteor 1.*并开始,我只是使用帐户密码.

参考代码

我有一个简单的服务器端路由,将pdf呈现给屏幕:

两者/ routes.js

Router.route('/pdf-server', function() {
  var filePath = process.env.PWD + "/server/.files/users/test.pdf";
  console.log(filePath);
  var fs = Npm.require('fs');
  var data = fs.readFileSync(filePath);
  this.response.write(data);
  this.response.end();
}, {where: 'server'});
Run Code Online (Sandbox Code Playgroud)

举个例子,我想做一些接近SO答案建议的事情:

在服务器上:

var Secrets = new Meteor.Collection("secrets"); 

Meteor.methods({
  getSecretKey: function () {
    if (!this.userId)
      // check if the user has privileges
      throw Meteor.Error(403);
    return Secrets.insert({_id: Random.id(), user: this.userId});
  },
});
Run Code Online (Sandbox Code Playgroud)

然后在客户端代码中:

testController.events({
  'click button[name=get-pdf]': function () {
      Meteor.call("getSecretKey", function (error, response) {
        if (error) throw …
Run Code Online (Sandbox Code Playgroud)

authentication routing node.js meteor iron-router

10
推荐指数
3
解决办法
4382
查看次数

铁路由器服务器端的Meteor.user()

如何在服务器端路由上检查用户是否已登录?

我会在'之前'添加检查,但是Metor.user()在这里不起作用.

提前致谢.

ps我发现如何让Meteor.user()返回服务器端?,但不适用于铁路由器

meteor iron-router

9
推荐指数
1
解决办法
1654
查看次数

使用Iron Router进行waitOn订阅,该订阅依赖于来自其他订阅的文档的数据

我在配置waitOn路由的一部分时遇到问题,其中一个订阅的参数由来自不同订阅的文档中的值确定.

游戏中的收藏品是候选人和访谈.面试将只有一名候选人.这是一些示例数据:

candidate = {
    _id: 1
    firstName: 'Some',
    lastName: 'Developer'
    //other props
};

interview = { 
    _id: 1,
    candidateId: 1
    //other props
};
Run Code Online (Sandbox Code Playgroud)

路由配置如下.

this.route('conductInterview', {
    path: '/interviews/:_id/conduct', //:_id is the interviewId
    waitOn: function () {
        return [
            Meteor.subscribe('allUsers'),
            Meteor.subscribe('singleInterview', this.params._id),
            // don't know the candidateId to lookup because it's stored
            // in the interview doc
            Meteor.subscribe('singleCandidate', ???), 
            Meteor.subscribe('questions'),
            Meteor.subscribe('allUsers')
        ];
    },
    data: function () {
        var interview = Interviews.findOne(this.params._id);
        return {
            interview: interview,
            candidate: Candidates.findOne(interview.candidateId);
        }; …
Run Code Online (Sandbox Code Playgroud)

meteor iron-router

9
推荐指数
2
解决办法
1558
查看次数

Meteor:使用Iron Router的用户配置文件页面

我正在努力创建一个用户配置文件页面,使用位于的铁路由器localhost:3000/:username.配置文件页面应具有以下特征:

  • 公共视图 - 任何人都可以看到有关用户的基本信息
  • 私人视图 - 如果客户在登录时访问他或她自己的个人资料页面,则会显示他或她的敏感用户数据,并且他们具有编辑功能
  • 加载视图 - 在提取用户配置文件数据时,显示加载屏幕
  • 找不到视图 - 如果在URL中输入了无效的用户名,则返回未找到的页面.

公共视图和私有视图应存在于同一 URL路径中.根据客户端的凭据,他们会看到一个或另一个没有重定向到其他页面.未找到的页面也不应该重定向,这样如果输入无效的用户名,用户仍然可以在浏览器URL栏中看到无效的URL.

我的router.js文件:

this.route('profile', {
    controller: 'ProfileController',
    path: '/:username'
  });
Run Code Online (Sandbox Code Playgroud)

在内ProfileController,我正在努力拼凑以下内容:

  • onBeforeAction - 显示加载屏幕; 确定用户名是否存在(即URL是否有效)
    • 显示未找到的视图,私人个人资料或公开个人资料
  • waitOn- username在删除加载屏幕之前等待检索数据
  • onAfterAction - 删除加载屏幕

谢谢!

javascript meteor iron-router

9
推荐指数
1
解决办法
3884
查看次数

Meteor,Iron:路由器在Router.go上传递多个属性

我的困境是我想将多个对象属性传递给一个铁:Meteor中的路由器路由.原因是我想传递一个属性来命名我的url和一个属性来查找一个集合项目.它们完全相互独立,我不能使用url属性,因为它不是集合项中的值.这就是我所拥有的:

Template.items.events({
'click': function () {
    itemName = this.name.replace(/ /g,'')
    Router.go('itemDetails', {itemName: itemName})
    }
});
Run Code Online (Sandbox Code Playgroud)

问题是虽然路由器处理这个问题并将我发送到正确的URL,但我不能itemName用来找到我正在寻找的集合项对象(假设这是不可能的).

Router.route('/items/:itemName', {
    name: 'itemDetails', 
    data: function() {return Items.findOne({name: this.params.itemName})}
});
Run Code Online (Sandbox Code Playgroud)

上面的路由器配置不会返回任何内容,因为name != this.params.itemName任何对象.

我试过传递this对象,或者创建具有多个属性的对象,但铁:路由器不会有它.

任何帮助表示赞赏,谢谢.

编辑#1:为了帮助进一步解释问题,我的问题与路由到在URL中使用多个ID的页面相同.例如,我如何将属性传递给iron:路由器来填充:_id:itemId属性?

Router.route('items/:_id/:_itemId', {
    name: 'detailDetails',
    data: function() {...}
});
Run Code Online (Sandbox Code Playgroud)

编辑#2:我特别想要做的是将两个属性传递给iron:router并将其中一个属性附加到URL,另一个用于路由的data属性以返回集合项.例:

....
    Router.go('itemDetails', {_id: itemBeingPassedId, itemName: nameToBeAppendedToURL})
....

Router.route('/items/:itemName', {
    name: 'itemDetails',
    data: function(){return Items.findOne(_id)
});
Run Code Online (Sandbox Code Playgroud)

每当我尝试这样做时,它都表示_id未定义.所以基本上,我怎样才能将属性传递给dataURL,而不将其作为URL的一部分并使用this.params

javascript routes meteor iron-router

9
推荐指数
1
解决办法
5721
查看次数

如何使用Iron Router返回404

当我点击我使用IR的Meteor应用程序上不存在的路径时,我得到一个200带有HTML 的响应(当在浏览器上呈现时)在控制台上显示js错误No route found for path: "/aRoute".

如何让它回归404

meteor iron-router

9
推荐指数
2
解决办法
3979
查看次数

在Meteor中正确使用onResetPasswordLink,onEnrollmentLink和onEmailVerificationLink方法

我想知道是否有人能够提供一个meteorpad或代码示例,在Meteor中正确使用上面列出的方法之一(使用铁:路由器).我很难理解这些方法究竟是如何与我的应用程序交互的,而且看起来这些方法已经足够新,以至于没有很多关于如何正确使用它们的良好文档.谢谢!

http://docs.meteor.com/#/full/Accounts-onResetPasswordLink

meteor iron-router meteor-accounts

9
推荐指数
2
解决办法
2862
查看次数