Meteor Iron-Router Without Layout Template or JSON View

前端 未结 2 824
生来不讨喜
生来不讨喜 2021-01-14 15:33

Using Meteor Iron-Router how can I either render data as JSON or simply display it \"raw\" (without a layout template)

Essentially I want to be able to do s

相关标签:
2条回答
  • 2021-01-14 16:00

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

    (Note the comment amending the content type.)

    0 讨论(0)
  • 2021-01-14 16:02

    Make a raw layout template

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

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

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

    I'm not sure whether you're using this as a placeholder for your actual code. If you intend to render data using JSON or actual raw text. You might want to consider using server-side routes. You should do something like this instead:

    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));
      }
    });
    

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

    0 讨论(0)
提交回复
热议问题