iron-router

Meteor : how to publish custom JSON data?

寵の児 提交于 2019-12-01 00:12:18
Edit: The solution I used is @Kyll's one. Suppose the server side objects I'd like to return are "complicated" to build and need different attributes from different collections. I first tried: /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'}, (...) ]; }); It doesn't work because it's not returning a cursor. What I want to do is

How to return 404 using Iron Router

别等时光非礼了梦想. 提交于 2019-12-01 00:11:10
问题 When I hit a route that doesn't exist on my Meteor app that uses IR, I get a 200 response with an HTML that (when rendered on a browser) displays a js error on console saying that No route found for path: "/aRoute" . How can a make it return 404 ? 回答1: There don't seem to be a correct (or even working?) way of handling real 404's right now. See this issue for example: https://github.com/EventedMind/iron-router/issues/1055 Even when you try ways which should work, you'll still end up with a

Meteor.user() on iron-router server side

南笙酒味 提交于 2019-11-30 18:54:26
How can check, on server side route, if user is logged? I would add check on 'before', but Metor.user() don't work here. thanks in advance. p.s. I have found How to get Meteor.user() to return on the server side? , but not work on iron-router I'm afraid that this is not possible. I guess that the problem comes from the fact that you're trying to connect to the server with two different protocols - both literally and in logically - so there is no obvious way to relate this two actions. There is, however, a pretty simple solution that may suit your needs. You'll need to develop a simple system

Multiple yield in Meteor.js application template

≯℡__Kan透↙ 提交于 2019-11-30 15:21:44
I have one general {{>yield}} for iron-router in a layout file which renders my pages, which are templates. In one of my pages, I have a side menu and according to the selection in this menu, I want to load different templates related to this page in this page. How can I achieve this? I have done a similar thing using iron-router's layout template option. Say I want to create a home view with multiple views/templates inside of this home view that will change. First I would declare my route: Router.map(function () { this.route('home', { path: '/', template: 'myHomeTemplate', layoutTemplate:

Exception when using a server route and onBeforeAction

我与影子孤独终老i 提交于 2019-11-30 10:01:31
问题 I'm seeing strange behavior when trying to add pdf file generation. The following code, on the if statement, throws: both\routes.js Router.onBeforeAction(function () { if (!Meteor.user() || Meteor.loggingIn()) { this.redirect('welcome.view'); } else { Meteor.call("userFileDirectory", function (error, result) { if (error) throw error; else console.log(result); }); this.next(); } }, { except: ['welcome.view'] }); Error: Meteor.userId can only be invoked in method calls. Use this.userId in

Meteor: Call function after template is rendered with data

自闭症网瘾萝莉.ら 提交于 2019-11-30 05:59:50
问题 I have a number of posts that I want to display inside of a carousel. For the carousel, I use OwlCarousel . <div class="owl-carousel" id="featured-carousel"> {{#each featuredPosts}} <div> <h2> {{postTitle}} </h2> </div> {{/each}} </div> I call my carousel like so: Template.featuredCarousel.rendered = function(){ $('#featured-carousel').owlCarousel({ loop:true, autoplay:true, autoplayTimeout:3000, items:1, smartSpeed:1080, padding:80 }); this.rendered = true; }; The result I get is that Owl

Meteor.user() on iron-router server side

社会主义新天地 提交于 2019-11-30 03:37:30
问题 How can check, on server side route, if user is logged? I would add check on 'before', but Metor.user() don't work here. thanks in advance. p.s. I have found How to get Meteor.user() to return on the server side?, but not work on iron-router 回答1: I'm afraid that this is not possible. I guess that the problem comes from the fact that you're trying to connect to the server with two different protocols - both literally and in logically - so there is no obvious way to relate this two actions.

How to pass a parameter to pathFor in Handlebars for Iron-Router with Meteorite?

╄→гoц情女王★ 提交于 2019-11-29 20:22:06
I have a simple route with a parameter: this.route('article', { path: '/article/:_id', data: function() { return Articles.findOne(this.params._id); } }); I would like to have use the pathFor handlebars helper here with the _id: {{#each articles}} <li><a href="{{pathFor 'article' _id}}">{{title}}</a></li> {{/each}} This doesnt work for passing the _id tag into the url though... <li><a href="{{pathFor 'article' _id=this._id }}">{{title}}</a></li> Thats how you pass a parameter In your example you don't need to pass any parameters. The pathFor helper will automatically use the current data

Meteor: Why is Iron Router's onBeforeAction called multiple times?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 14:22:53
When I visit a route in my browser I expect Iron Router to call onBeforeAction once before loading the route. But it looks like it is being called 3 times when first loading the route. This is an issue for me because I want to put code that redirects the user if they do not have access to that document. onBeforeAction: -> console.log 'called once' #Called 3 times when first loading the route! thread = Research.findOne(@params._id) console.log thread # This is undefined at first run thread = Research.findOne(@params._id) if thread? Meteor.subscribe 'collabUsers', @params._id else Router.go '

When using a regex in iron router, how to access the match?

烂漫一生 提交于 2019-11-29 13:15:34
Rather than having five different routes, I am trying to combined five different paths into a single function, but I still need to know which path it matched. So if I set up my route using a regex: Router.route(/^\/(accounts)|(contacts)|(forecasts)|(analytics)|(activities)/, function() { // which one did it match? console.log("matched "+this.params) //this returns an array of five params } how do I refer to the matched parameter inside the function? this.params returns an array of five params with four of them undefined and the other matching, but which one is defined depends on what matched