iron-meteor / iron-router

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

Calling pathFor from another helper #1483

Open edemaine opened 8 years ago

edemaine commented 8 years ago

I've found that I can call the pathFor helper from another helper using the following CoffeeScript function:

  @pathFor = (route, args) ->
    Blaze._globalHelpers.pathFor
      hash:
        route: route
        data: args

The question is, why did I have to wrap everything in "hash"? In other words, can anyone explain var opts = options && options.hash; (line 32 of lib/helpers.js)? It seems this replaces options with options.hash but ... why? Is there something magic about helpers I don't understand? There is similar code in urlFor, but something else in linkTo.

As an aside, it's be really nice to have a function like the above in the API, unless Meteor someday allows calling helpers from each other... Essentially, Router.go but returning a URL instead of going there.