How can I dynamically set router options in a Meteor application using the iron router package? -
i set route option label of current url, e.g.
router.route('/:_url', { label: '_url', action: function () { this.render('home'); } });
this helper:
if (meteor.isclient) { template.home.helpers({ getlabel: function() { return router.current().route.options.label; } }); }
this template:
<template name="home"> hi {{getlabel}} </template>
when visit locolhost:3000/alexander
should see hi alexander
see hi _url
how can _url variable correctly resolve see hi alexander
?
router.route("/:name", { name: "home", template: "home", data: function(){ // create new key myname on route object route // , set value name user entered in path this.route.options.myname = this.params.name; return { label: this.params.name }; } }); // routes stored in router.routes array // loop through find 1 myname key , return value (var = 0; < router.routes.length; i++){ if (router.routes[i].options.myname){ console.log(router.routes[i].options.myname); } }
Comments
Post a Comment