Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

Solution 2:

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

activate: function (params) {

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

    returntrue;
}

Solution 3:

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

Post a Comment for "Where Does Durandal Router Set Page Title"