iron-meteor / iron-router

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

Maybe expose something similar to this #1470

Closed talha-asad closed 8 years ago

talha-asad commented 8 years ago

router.current() is evil

Router.current() is evil. Why? Let's look at following example. Imagine we have a route like this in our app:

/apps/:appId/:section

Now let's say, we need to get appId from the URL. Then we will do, something like this in Iron Router.

Templates['foo'].helpers({
    "someData": function() {
        var appId = Router.current().params.appId;
        return doSomething(appId);
    }
});

Let's say we changed :section in the route. Then the above helper also gets rerun. If we add a query param to the URL, it gets rerun. That's because Router.current() looks for changes in the route(or URL). But in any of above cases, appId didn't get changed.

Because of this, a lot parts of our app get re-run and re-rendered. This creates unpredictable rendering behaviour in our app.

FlowRouter fixes this issue by providing the Router.getParam() API.

Seems like a valid point, can we get a similar exposed function in iron router?

chrisbutler commented 8 years ago

duplicate of https://github.com/iron-meteor/iron-router/issues/1316, but definitely a good idea