Links in Template

What is the difference between

       <a href="/requestdetails">Click</a>

and

      {{link-to 'requestdetails'}}Click{{link-to}}

If both of them same, why we need link-to helper . Please assist me on this

What’s great with the link-to helper is that you don’t pass the URL, but instead the name of the route. Consider this:

App.Router.map(function() {
  this.route("about", { path: "/this-is-the-about-url" });
});

By using {{#link-to 'about'}}About{{/link-to}} Ember will handle the correct URL for you.

You would also want to use the link-to helper for passing models:

<ul>
  {{#each post in posts}}
    <li>{{link-to post.title 'post' post}}</li>
  {{/each}}
</ul>

…this would generate the link /post/123 (where 123 is the post’s ID) for you and bypass the PostRoute´s model hook since you already have the post model available.

1 Like