DEV Community

Sivasubramanian
Sivasubramanian

Posted on

 

Passing pre-computed routes to link-to helper in Ember

Syntax

{{link-to routeName  dynamicSegment1 dynamicSegment2 (query-params key1=value1 key2=value2)}}

(or)

{{link-to params=linkParameters}}
Enter fullscreen mode Exit fullscreen mode

Description

Consider a photo application with below routes

this.route('photos', function() {
  this.route('resolution', {
    path: '/:value'
  });
});
Enter fullscreen mode Exit fullscreen mode

Compute links in component

linkParametersVariation1: computed({
  get() {
    let resolution = get(this, 'resolution);
    return { 'routeName': 'photos/resolution', dynamicSegment: resolution, page: 1, perPage: 30 }
  }
}),

linkParametersVariation2: computed({
  get() {
    let resolution = get(this, 'resolution);
    return ['photos/resolution', resolution, { isQueryParams: true, values: { page: 1, perPage: 30 } }]
  }
})
Enter fullscreen mode Exit fullscreen mode

Using links in template

{{#link-to linkParametersVariation1.routName linkParametersVariation1.dynamicSegment (query-params page=linkParametersVariation1.page perPage=linkParametersVariation1.perPage)}}
  <div>variation1</div>
{{/link-to}}

{{#link-to params=linkParametersVariation2}}
  <div>variation2</div>
{{/link-to}}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.