Search code examples
meteoriron-router

How to get path by name ? (meteor iron router)


I want to get a path by name, but I can't find which function I can use.. the iron-router guid is not that clear.. Thank you!!

Router.route('/path', {
name: 'newsPage'});

var path = Router.getPath('newsPage');// something like this

Solution

  • That woud be Router.path("newsPage").

    You can pass this function 2 additional parameters :

    • a context object (key / value dictionary) whose keys will be replaced in the path, ie if your route path is /user/:username then if you call Router.path("userProfile",Meteor.user()), you will get the path to the currently connected user profile.

    • an object to indicate query string parameters and hash value, ie this call Router.path("newsPage",{},{query:{ts:Date.now()},hash:"about"}) will give you this path : /path?ts=1433109536938#about.