iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 412 forks source link

can't add routes at runtime (asynchronously), latency with the meteor methods #1269

Open andresfelipemendez opened 9 years ago

andresfelipemendez commented 9 years ago

how can i add routes asynchronously?

i have a meteor method in lib/server/plugins.js

Meteor.methods({
  getPlugins: function() {
    return [
      { path: 'test' },
      { path: 'test2' }
    ]
  }
});

and my router config file in lib/routes.js

Router.route('/', function() {
    this.render('home');
}); 

Meteor.call('getPlugins', function(e,r) {
    if(!e) {
        for(var plugin in r) {
            function() {
                this.route(r[plugin].name);
            })
        }
    } else {
        console.log(e);
    }
})

var routes  = [
    { path: '/test3' },
    { path: '/test4' }
]

for(var i in routes) {
    Router.map(function() {
        this.route(routes[i].path);
    });
}

all the routes in the local variable routes works fine, but the routes that come from getPlugins iron router say Oops, looks like there's no route on the client or the server for url: "http://localhost:3000/test2."

musemind commented 9 years ago

Got the same problem. Application users should be able to create routes themself. New route definitions does not work after inital application load.

andresfelipemendez commented 9 years ago

i fixed it usign '/:paramenter' the sub routes as variables then calling the templates with the same name

musemind commented 9 years ago

Thank you! That was helpful.

Am 20.05.2015 um 00:18 schrieb Felipe notifications@github.com:

i fixed it usign '/:paramenter' the sub routes as variables then calling the templates with the same name

— Reply to this email directly or view it on GitHub https://github.com/iron-meteor/iron-router/issues/1269#issuecomment-103682902.