How to check for Route through route name in template with Meteor and Iron Router

南楼画角 提交于 2019-12-17 23:44:22

问题


What can I use in a template to figure out the route name that is associated with the route that I am currently on?

For example if I configured a route like so in iron-router

this.route('quick', {
    path: '/wow/:_id',
    template: 'create_question'
});

So if I am on the route /wow/123 how can I get the router's name in my template, in this case how can I get quick in my template?

I'm simply looking for a function, I am sure I can use a handlebars helper to get the rest done. I just need a function to call.


回答1:


iron-router > 1.0

var routeName = Router.current().route.getName();

iron-router < 1.0

var routeName = Router.current().route.name;



回答2:


For the newer iron router, use:

var routeName = Router.current().route.getName()

This will output the name of the actual route you defined with this.route()




回答3:


You can define any options you want in your route config :

Router.route('/', {
    name : 'home',
    template : 'home',
    title: 'Home'
});

and then access to title with this :

Router.current().route.options.title

This will output "Home"




回答4:


You can try Router.current().template



来源:https://stackoverflow.com/questions/22213122/how-to-check-for-route-through-route-name-in-template-with-meteor-and-iron-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!