pthalacker
pthalacker

Reputation: 2124

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

Upvotes: 3

Views: 1843

Answers (3)

SFlagg
SFlagg

Reputation: 369

Replacing page titles in Durandal 2.1.0

(if you want to the page title to be something distinct from the last level of the route)

Slight modification to RainerAtSpirit's answer: Specify 'title' in the route instead of 'name'.

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

Upvotes: 0

Szili
Szili

Reputation: 261

You can set the page title when the viewmodel gets activated:

activate: function (params) {

    // Setting page title
    params.routeInfo.caption = "My Page Title";

    return true;
}

Upvotes: 1

RainerAtSpirit
RainerAtSpirit

Reputation: 3723

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' },...
]);

Upvotes: 4

Related Questions