Search code examples
javascriptdurandal

Where does Durandal router set page title


I am using Durandal for a very simple website. In all of my browser tabs the page title is coming up with "undefined|" appended to the front of the application's title. Where is Durandal getting and setting that value?

pthalacker


Solution

  • Ultimately Durandal's router plugin is setting the document.title.

    https://github.com/dFiddle/dFiddle-1.2/blob/gh-pages/App/durandal/plugins/router.js#L254

    onNavigationComplete: function (routeInfo, params, module) {
        if (app.title) {
            document.title = routeInfo.caption + " | " + app.title;
        } else {
            document.title = routeInfo.caption;
        }
    },...
    

    Typically Durandal is able to construct a missing caption propterty on the route object, so maybe there's something different in the way the routes are set up.

    https://github.com/dFiddle/dFiddle-1.2/blob/gh-pages/App/samples/shell.js#L6

    router.map([
    
       { url: 'hello', moduleId: 'samples/hello/index', name: 'Hello World', visible: true },
       { url: 'hello/:name', moduleId: 'samples/hello/index', name: 'Examples' },...
    ]);