Meteor Iron-Router without template template or JSON View

Using a Meteor Iron-Router, how can I either display data as JSON, or just display its "raw" (without a layout template)

Essentially, I want to be able to do something like:

this.route('rawdata', { path: '/raw/:collection', layoutTemplate: 'nolayout', template: 'raw' }) 

where / raw / posts will display raw json posts (collection).

Thanks!

Notes

I know the JSON endpoint in Meteor. But the meteor router is terminated, and the Iron-Router does not have a JSON-end-point function.

I also looked at https://atmospherejs.com/package/collection-api , but it does not suit my needs, because I need the ability to select a subset of the collection / record field.

+3
source share
2 answers

Make Original Layout Template

 <template name="direct_layout"> {{> yield}} </template> 

Then use this as your layoutTemplate to use your template directly.

 this.route('rawdata', { path: '/raw/:collection', layoutTemplate: 'direct_layout', template: 'raw' }); 

I'm not sure if you use this as a placeholder for your actual code. If you are going to display data using JSON or the actual source text. You might want to use server routes. Instead, you should do something like this:

Please note that this is server-side code, unlike the above, which runs on the client side:

 this.route('serverRoute', { where: 'server', path: '/your-route', action: function() { var data = {this_is:'a json object'} this.response.writeHead(200, {'Content-Type': 'application/json'}); this.response.end(JSON.stringify(data)); } }); 

Look at server-side rendering on Iron-Router: https://github.com/EventedMind/iron-router/blob/master/DOCS.md#server-side-routing

+10
source

See: https://github.com/EventedMind/iron-router/issues/114

(Note the comment changing the type of content.)

+2
source

All Articles