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

前端 未结 4 672
你的背包
你的背包 2020-12-14 08:14

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

相关标签:
4条回答
  • 2020-12-14 08:22

    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"

    0 讨论(0)
  • 2020-12-14 08:33

    iron-router > 1.0

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

    iron-router < 1.0

    var routeName = Router.current().route.name;
    
    0 讨论(0)
  • 2020-12-14 08:38

    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()

    0 讨论(0)
  • 2020-12-14 08:41

    You can try Router.current().template

    0 讨论(0)
提交回复
热议问题