kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 193 forks source link

Can routes be extended? #558

Closed JulianKingman closed 8 years ago

JulianKingman commented 8 years ago

For example, this route from telescope:

FlowRouter.route('/submit', {
  name: "postSubmit",
  action: function(params, queryParams) {
    BlazeLayout.render("layout", {main: "post_submit"});
  }
});

Can I add more actions to the route? Something like this would be ideal:

FlowRouter.routes.postSubmit.action.extend = function(params, queryParams){
    console.log('Hey, a new action!');
}
JulianKingman commented 8 years ago

For further context, the main reason I want this is for package architecture, where the routes are already declared, and there are certain things I want to do (like render new elements) that should clearly be handled by the router, but for which I'm using really hacky things (like checking the route and rendering different things conditionally, basically making my own router).

Dev1an commented 8 years ago

I think you can use triggers for this. Instead of extending the action, like you propose, add a trigger for that route.

JulianKingman commented 8 years ago

That seems like a pretty good solution. I'll give that a shot and post back my results.

JulianKingman commented 8 years ago

For reference, here's the way to do it:

FlowRouter.triggers.enter([
  function () {
  //If you choose to render, also render the things that were already rendered in the original route
    BlazeLayout.render('layout', {
      main: "example_template",
      newZone: 'another_template'
    });
    console.log('on extended route');
  }
], {
  only: ["RouteNameGoesHere"]
});