Skip to content

Commit 4eccc4c

Browse files
authored
Aurelia optional route (#6)
* Aurelia - optional route with place holder for contact creation * Remove click delegate on create new contact
1 parent 34c20d3 commit 4eccc4c

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

ASP.NET Core Basics/src/Aurelia/ClientApp/app/components/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class App {
3737
title: 'Contact List'
3838
},
3939
{
40-
route: 'contact-detail/:id',
40+
route: 'contact-detail/:id?',
4141
name: 'contactdetail',
4242
moduleId: '../contacts/contactDetail',
4343
nav: false,

ASP.NET Core Basics/src/Aurelia/ClientApp/app/components/contacts/contactDetail.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ <h1>Contact Details</h1>
1515
<dd>${contact.email}</dd>
1616
</dl>
1717
</div>
18+
<h3 if.bind="!hasContactId">
19+
Place holder for creating a new contact
20+
</h3>
1821
<a route-href="route: contactlist">Back to List</a>
1922
<hr />
2023
</template>

ASP.NET Core Basics/src/Aurelia/ClientApp/app/components/contacts/contactDetail.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import { ContactService } from './contactService';
55
@inject(ContactService)
66
export class ContactDetail {
77
contact: Contact;
8+
hasContactId: boolean;
89

910
constructor(private contactService: ContactService) { }
1011

1112
activate(parms, routeConfig) {
12-
return this.contactService.getById(parms.id)
13-
.then(contact => this.contact = contact);
13+
this.hasContactId = parms.id;
14+
15+
if (this.hasContactId) {
16+
return this.contactService.getById(parms.id)
17+
.then(contact => this.contact = contact);
18+
}
19+
20+
return null;
21+
1422
}
1523

1624
}

ASP.NET Core Basics/src/Aurelia/ClientApp/app/components/contacts/contactList.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<h1>Contact List</h1>
33

44
<p if.bind="!contacts"><em>Loading...</em></p>
5+
6+
<a route-href="route: contactdetail">Create New Contact</a>
57

68
<table class="table" if.bind="contacts">
79
<thead>

0 commit comments

Comments
 (0)