Routing Helpers
Learn how to change the root URL and how to create helper functions for routing in Marionette.
We'll cover the following...
Redirecting to #contacts
at root URL
Here’s what we want to do if a user comes to our app at the root URL. We redirect them to #contacts
.
The basic way of accomplishing this is the following:
Press + to interact
ContactManager.on("start", function(){if(Backbone.history){Backbone.history.start();if(Backbone.history.fragment === ""){Backbone.history.navigate("contacts");ContactManager.ContactsApp.List.Controller.listContacts();}}});
In line 5, we check the URL fragment, i.e., the string that comes after index.html
in the URL, ignoring the #
character. If it’s empty, we need to redirect the user. However, in JavaScript web apps, ...