Define a Router
A Backbone router defines navigation paths among views.
-
In the final
<script>
block, define the application router by extendingBackbone.StackRouter
.For the remainder of this procedure, add all code in the
extend({})
block. -
Because the app supports a search list page and a user page, add a route for each page inside a
routes
object. Also add a route for the main container page (""). -
Define an
initialize()
function that creates the search results collection and the search page and user page views. -
Define the
list()
function for handling the only item in this route. CallslidePage()
to show the search results page right away—when data arrives, the list redraws itself. -
Define a
viewUser()
function that fetches and displays details for a specific user. -
After saving the file, run the
cordova prepare
command. -
Run the application.
You’ve finished! Here’s the entire application: