Default Route Values

Most web-apps have a default values for things when the page first loads. The routing system needs to be aware of these default values in case other values change that are later on in the routing url.

For example a book store might have a list page to present to a user, and you might have a grid that is sorted by book title by default. Without defaults this might look like:

http://example.com/#!/list/title/down

We can specify default values for these variables in the code:

$.hr.setDefault('page', 'list'); $.hr.setDefault('sort', 'title'); $.hr.setDefault('direction', 'down');

When a user first loads the page these values will be used only if they aren't specified in the url.

http://example.com/

When a user clicks the 'title' column to sort it in the other direction, the routing system fills in the other default values:

http://example.com/#!/list/title/up

You can try it on the optional routes page which uses default values for the circle colors. As you hover over the bottom three links note the length of the URL increases as default values are filled in.