A post covering the same concepts but with updated versions of ASP.NET and Aurelia can be found here.
I have spent some time building out the client side of my contacts application using Aurelia. For a starting point with Aurelia check out my previous post on Aurelia with ASP.NET 5 and Web API and Start Aurelia from an ASP.NET 5 Controller. In this post I am going to cover passing a parameter via routing.
Keep in mind I am serving this application from ASP.NET 5 and all the Aurelia related files are in the wwwroot folder of my ASP.NET 5 project. App.html and app.js in wwwroot with the remaining Aurelia files in an Aurelia folder.

In app.js a new route was added for the detail view. Make special note that the new route expects an id parameter.
import 'lib/bootstrap/dist/js/bootstrap';
export class App {
configureRouter(config, router) {
config.title = 'Contacts';
config.map([
{
route: ['', 'list'],
name: 'list',
moduleId: './Aurelia/list',
nav: true,
title: 'List'
},
{
route: 'add',
name: 'add',
moduleId: './Aurelia/add',
nav: true,
title: 'Add'
},
{
route: 'detail/:id',
name: 'detail',
moduleId: './Aurelia/detail',
nav: false,
title: 'Detail'
}
]);
this.router = router;
}
}
In list.html the contacts need to be rendered with an anchor that will lead to the proper detail view. To accomplish this Aurelia has a route-href custom attribute that can be used with an anchor.
<template>
<div>
<ul class="list-group">
<li repeat.for="contact of contacts" class="list-group-item">
<h4 class="list-group-item-heading">
<a route-href="route: detail;
params.bind: {id:contact.Id}">
${contact.Name}
</a>
</h4>
<p repeat.for="emailaddress of contact.EmailAddresses"
class="list-group-item-text">
<a href="mailto:${emailaddress.Address}">
${emailaddress.Address}
</a>
</p>
</li>
</ul>
</div>
</template>
With route-href route, set to detail above, defines the name of the route from the route config. Parms.bind creates an object with an id property which is bound to the id defined on the route. Any property on the object that does not have a in the route definition will be added to the query string.
When one of the routing links is clicked then on activation detail.js queries the Web API for the contact details based on the id in the parms.
import {inject} from 'aurelia-framework';
import {HttpClient, json} from 'aurelia-fetch-client';
import 'fetch';
@inject(HttpClient)
export class Detail{
contact = '';
constructor(http){
http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('https://localhost:13102/api/');
});
this.http = http;
}
activate(params) {
return this.http.fetch('contacts/' + params.id)
.then(response => response.json())
.then(contact => this.contact = contact);
}
}
No real new concepts in the above. On active the Web API is called and the resulting json is used to populate a contact property.
The detail view then uses the contact property to bind to the contact information.
<template>
<div>
<div class="row">
<label class="label label-info">${contact.Id}</label>
</div>
<div class="row">
<label class="col-sm-1 control-label">Name</label>
<div class="col-sm-11">
<p class="control-label">${contact.Name}</p>
</div>
</div>
<div class="row">
<label class="col-sm-1 control-label">Addresses</label>
<div class="col-sm-11">
<p repeat.for="address of contact.Addresses"
class="list-group-item-text">
${address.City}, ${address.State}
</p>
</div>
</div>
<div class="row">
<label class="col-sm-1 control-label">Email Addresses</label>
<div class="col-sm-11">
<p repeat.for="emailaddress of contact.EmailAddresses"
class="list-group-item-text">
<a href="mailto:${emailaddress.Address}">${emailaddress.Address}</a>
</p>
</div>
</div>
<div class="row">
<label class="col-sm-1 control-label">Phone Numbers</label>
<div class="col-sm-11">
<p repeat.for="phone of contact.PhoneNumbers"
class="list-group-item-text">
${phone.Number}
</p>
</div>
</div>
</div>
</template>
The above results in the following view.
