简体   繁体   中英

how i can do nested levels with iron-router in meteor?

i am new in iron-router, here is the problem(code given below)

using meteorite & meteor 0.8.1

App.Router.map(function() {
  this.resource('post', { path: '/post/:post_id' }, function() {
    this.route('edit');
    this.resource('comments', function() {
      this.route('new');
    });
  });
});

this is the case that worked perfectly in emberjs router, how i solve this type nested levels of routing in meteor with iron-router ?

thinking it can be solved with session ??

in router

this.route("v", {onBeforeAction: function() {Session.set('uniqueId', this.params._id);}, path: "/v/:_id"});

in Template.v.events

"click #v": function(event, target) {
event.preventDefault();

Accounts.verifyEmail(Session.get('uniqueId'), function(error) {
    if(error) throwError(error.reason); else Meteor.Router.to("/profile");
});

Are you trying to mix code from different frameworks ? I'm not exactly sur of what you are trying to do, but if your router works and you want to access your datas in your template, you should use the template data context.

If your route is defined that way :

this.route('your.route', {path: '/yourroute/:_id'});

In the controller of your route, you can try this :

YourTemplateController = RouteController.extend({
    waitOn: function () {
    },

    data: function () {
        return this.params._id;
    },

    action: function () {
        this.render();
    }
});

The this.params._id is now accessible in your template events that way :

Template.YourTemplate.events({

    "click #v": function(event, template) {
        console.log(template.data);
    }

)};

Note that the second argument for the events object is the template, not a target.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM