How to toggle between links in ember.js?

Member

by lottie , in category: Javascript , 4 months ago

How to toggle between links in ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , 4 months ago

@lottie 

You can toggle between links in Ember.js by using the {{#link-to}} helper in your templates.


For example, if you have two links in your template, you can use a conditional statement to toggle between them based on a property in your component or controller.

1
2
3
4
5
{{#if isLink1Active}}
  {{#link-to 'route1'}}Link 1{{/link-to}}
{{else}}
  {{#link-to 'route2'}}Link 2{{/link-to}}
{{/if}}


In this example, isLink1Active is a property in your component or controller that determines which link should be displayed. When isLink1Active is true, Link 1 will be displayed and when it is false, Link 2 will be displayed.


You can then update the isLink1Active property based on a user action or some other event in your Ember application to toggle between the links.