Adding a Show Route

Learn how to separate the URLs of our contacts from the root URL based on their contact IDs using routing in Marionette.

Let’s add a route to show a given contact. In other words, we’ll add a route handler for URL fragments that look like contacts/3, where 3 would be the contact’s id.

Declaring routes for contacts

For declaring routes for contacts, we need to add their routing paths as a URL fragment, which will identify them uniquely based on their IDs.

Route using URL fragment

Let’s start by taking care of displaying the contact when a URL of this type is clicked, by adding it to our ContactsApp file:

Get hands-on with 1200+ tech skills courses.