Bootstrap dropdowns in Durandal 2.0

durandal, twitter-bootstrap

Solution

The problem was actually quite simple. There was no conflict with the routing module. I assumed the bootstrap javascript was included by default on the starter kit, but it is not.

The fix is as simple as adding an additional line to my require dependencies:

var system = require('durandal/system'),
    app = require('durandal/app'),
    viewLocator = require('durandal/viewLocator');
require('bootstrap');

Note that my require.config is:

require.config({
    paths: {
        'text': '../lib/require/text',
        'durandal':'../lib/durandal/js',
        'plugins' : '../lib/durandal/js/plugins',
        'transitions' : '../lib/durandal/js/transitions',
        'knockout': '../lib/knockout/knockout-2.3.0',
        'bootstrap': '../lib/bootstrap/js/bootstrap',
        'jquery': '../lib/jquery/jquery-1.9.1'
    },
    shim: {
        'bootstrap': {
            deps: ['jquery'],
            exports: 'jQuery'
       }
    }
});

Problem

I am trying to wire up some bootstrap dropdown navigation in a durandal 2.0 app: ``` <ul class="nav nav-pills"> <li class="dropdown"> <a class="dropdown-toggle" data-toggle="dropdown" href="#"> <span>Dropdown</span> <b class="caret"></b> </a> <ul class="dropdown-menu"> <li><a tabindex="-1" href="#/view/a>Option A</a></li> <li><a tabindex="-1" href="#/view/b">Option B</a></li> </ul> </li> </ul> ``` Clicking "dropdown" causes Durandal's router to attempt to navigate to the root route (which is "#" or ""). And never opens the menu. Is this correct? Workarounds? Update Tabs suffer the very same problem: ``` <div class="tabbable"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li> <li><a href="#tab2" data-toggle="tab">Section 2</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab1"> <p>I'm in Section 1.</p> </div> <div class="tab-pane" id="tab2"> <p>Howdy, I'm in Section 2.</p> </div> </div> </div> ```

Original source