el-lugy
el-lugy

Reputation: 408

Show/hide home button depending on route

I'm doing the first steps in Ember.js and I am quite confused by the different approaches and solutions provided in communities.

I have a quite small application that has a application template and content templates which I navigate through by link-to.

My application template has a home button which I want to hide and show depending on the route i am navigating to. How do I do that?

I am using plain-old JavaScript. No preprocessors or similar.

Upvotes: 0

Views: 787

Answers (1)

Bek
Bek

Reputation: 3207

you can use global currentRouteName property directly in your controller

in your application controller

hideHomeButtonRoutes: ['index', 'login'],
isHomeButtonVisible: Ember.computed('currentRouteName', function(){
  return this.get('hideHomeButtonRoutes').indexOf(this.get('currentRouteName')) > -1;
})

in your template

{{#if isHomeButtonVisible}} <button>home</button> {{/if}}

here is working example

Upvotes: 3

Related Questions