Define a Router

A Backbone router defines navigation paths among views. To learn more about routers, see What is a router?

  1. In the final <script> block, define the application router by extending Backbone.StackRouter.

    For the remainder of this procedure, add all code in the extend({}) block.

  2. 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 ("").

  3. Define an initialize() function that creates the search results collection and the search page and user page views.

  4. Define the list() function for handling the only item in this route. Call slidePage() to show the search results page right away—when data arrives, the list redraws itself.

  5. Define a viewUser() function that fetches and displays details for a specific user.

  6. After saving the file, run the cordova prepare command.

  7. Run the application.

You’ve finished! Here’s the entire application: