Ember.js Ember.Templates.helpers link-to() Method
Last Updated :
28 Nov, 2022
Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. Currently, it is utilized by many websites, including Square, Discourse, Groupon, Linked In, Live Nation, Twitch, and Chipotle.
The link-to() method is used to add the link-to-supplied route name passing as an optionally supplied model to the one route.
Syntax:
<#LinkTo @route='RouteName' />
Parameters:
- RouteName: It is the route name for which the link in rendered.
Steps to Install and Run Ember.js:
Step 1: To run the following examples you will need to have an ember project with you. To create one, you will need to install ember-cli first. Write the below code in the terminal:
npm install ember-cli
Step 2: Now you can create the project by typing in the following piece of code:
ember new <project-name> --lang en
To start the server, type:
ember serve
Example 1: Type the following code to generate the route for this example:
ember generate route link1
app/templates/array1.hbs
HTML
{{page-title "link"}}
< h2 >
Student list :
</ h2 >
{{#each
(array
"Arabh" "Pokhu" "Sam" "Ram" "Rohit" "Sam"
"Lalu" "Rahul" "Dadu" "Arabh"
)
as |name|
}}
< li >{{name}}</ li >
{{/each}}
|
app/templates/link1.hbs
HTML
{{page-title "link"}}
<#LinkTo @route={{'array1'}}>
Student in List
</ LinkTo >
|
Output:
Ember.js Ember.Templates.helpers link-to() Method
Example 2: Type the following code to generate the route for this example:
ember generate route link2
app/routes/list2.js
Javascript
import Route from '@ember/routing/route' ;
export default class List2Route extends Route {
students = {
name: 'Pokhraj Verma' ,
age: 23,
lan: 'Python' ,
deg: 'Btech'
}
model() {
return this .students;
}
setupController(controller, model) {
super .setupController(controller, model);
controller.set( 'students' , this .students);
}
}
|
app/templates/list2.hbs
HTML
{{page-title "List2"}}
< b >
{{#each-in @model as |key value|}}
{{key}}
:
{{value}}
< br />
{{/each-in}}
{{outlet}}
</ b >
|
app/templates/list1.hbs
HTML
{{page-title "List"}}
< h2 >Student Image</ h2 >
< img src = "/kitty.jpeg" alt = "" >
{{outlet}}
|
app/templates/link.hbs
HTML
{{page-title "Link2"}}
< h2 >
Student Profile:
</ h2 >
< LinkTo @route={{"list"}}>
Student Image
</ LinkTo >
< br />
< LinkTo @route={{"list2"}}>
Student Details
</ LinkTo >
{{outlet}}
|
Output:
Ember.js Ember.Templates.helpers link-to() Method
Reference: https://api.emberjs.com/ember/release/classes/Ember.Templates.components/methods/input?anchor=LinkTo
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...