documentcloud/backbone — pull request #1326 by tgriesser (2012-05-17 00:34:50+00:00)
Title: Adding History.segment() for URL segment retrieval

I've found myself grabbing specific URL segments outside of the router class (mainly when routing with *splats), and I've been using something similar to this in different places, so I thought it might be helpful to add this to Backbone.History as a convenience function.

Backbone.history.segment(index, [default]);

Usage for http://example.com/main/page/2 or http://example.com#main/page/2

`Backbone.history.segment(1) === 'main'`
`Backbone.history.segment(3) === '2'`
`Backbone.history.segment(4) === null`
`Backbone.history.segment(4, 'error') === 'error'`

Documentation and tests are included.

I've also added documentation for Backbone.history.getFragment(), which I noticed while looking through the history api, and is a great function to know about.