i.e. Jonathan Abbett — web crafter, healthcare designer, amateur kosher cheesemaker.

Getting normal URLs with Backbone, PushState, and Apache

19 March 2013
When you're tired of #

While developing the UI for, I've been using the hash-based URLs that work by default with the Backbone.js Router.

When it came time for automated browser testing with Selenium IDE, everything came to a halt. When Selenium opens a URL that's just a change of hash, it won't detect the (obviously visible) page change and the open command times out. (Unfortunately, my bug submission has yet to be addressed.)

So, I finally bit the bullet and set up my environment to support "normal" URLs. These were the basic steps (with links to the resources I consulted):

  1. Create/edit .htaccess file to rewrite URLs
  2. Add { pushState: true } option to Backbone.history.start()
  3. Edit all URLs in your code to remove the #/
  4. Add { trigger: true } option to all application.navigate() calls
  5. Hijack all internal link clicks and pass URLs to navigate() (thanks @tbranyen)
comments powered by Disqus
Uncaught Exception

Uncaught Exception

Array and string offset access syntax with curly braces is deprecated


anchor/libraries/markdown.php on line 1396


#0 [internal function]: System\Error::shutdown()
#1 {main}