iron-meteor / iron-router

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

Get pathFor / urlFor in javascript helper function #1373

Closed niranjans closed 9 years ago

niranjans commented 9 years ago

This seems to be a very simple thing and I think I'm missing something here but I can't seem to find how to get the complete URL to a particular page in Javacript similar to pathFor / urlFor.

I tried looking for this in the docs and the issues but couldn't get anything.

niranjans commented 9 years ago

I found the answer. Adding it here for others:

// returns '/posts/1'
Router.routes['postDetail'].path({_id: 1});
// returns 'http://localhost:3000/posts/1'
Router.routes['postDetail'].url({_id: 1});
neil-s commented 8 years ago

I really don't see why this isn't in the Guide, or anywhere else in the documentation. Sorry to bump an old thread, but could we please see this included in the docs? I came close to guessing this, but didn't think to name the params passed into .url().

MohammedEssehemy commented 6 years ago

for any one coming later adding to @niranjans answer you could also set query params as follows

Router.routes['postDetail'].path({_id: 1},{query:{q1:v1}});

Router.routes['postDetail'].url({_id: 1},{query:{q1:v1}});`