pilavdzice
pilavdzice

Reputation: 958

durandal routing error 'Cannot read property 'then' of undefined', what does it mean?

I am new to Durandal and just getting started with it. I started with the sample app and started modifying it but am running into this error with routing and I am stuck, please help:

Stack trace:

Uncaught TypeError: Cannot read property 'then' of undefined activator.js?bust=1386627525810:141 (anonymous function) activator.js?bust=1386627525810:141 jQuery.extend.Deferred jquery-1.9.1.js:1248 system.defer system.js?bust=1386627525810:218 canDeactivateItem activator.js?bust=1386627525810:130 computed.canDeactivateItem activator.js?bust=1386627525810:240 (anonymous function) activator.js?bust=1386627525810:300 jQuery.extend.Deferred jquery-1.9.1.js:1248 system.defer system.js?bust=1386627525810:218 computed.activateItem activator.js?bust=1386627525810:285 activateRoute router.js?bust=1386627525810:257 ensureActivation router.js?bust=1386627525810:328 (anonymous function) router.js?bust=1386627525810:360 (anonymous function) jquery-1.9.1.js:1192 fire jquery-1.9.1.js:1037 self.fireWith jquery-1.9.1.js:1148 deferred.(anonymous function) jquery-1.9.1.js:1237 (anonymous function)

My Shell.js looks like:

define(['plugins/router', 'durandal/app'], function (router, app) {
    return {
        router: router,
        search: function() {
            //It's really easy to show a message box.
            //You can add custom options too. Also, it returns a promise for the user's response.
            app.showMessage('Search not yet implemented...');
        },
        activate: function () {
            router.map([
                  { route: '', title: 'Budget', moduleId: 'viewmodels/budget' },
                  { route: 'Back', title: 'Back to User Screens', moduleId: 'viewmodels/back', nav: true },
                  { route: 'Budget', title: 'Budget', moduleId: 'viewmodels/budget', nav: true },


            ]).buildNavigationModel();

            return router.activate();
        }
    };
});

Back.js and back.html are basically empty like this, all I want this page to do do is redirect back to my old app, I want durandal as a new part of the application I am building and I am thinking of slowly migrating everything over into durandal:

define(['plugins/http', 'durandal/app', 'knockout'], function (http, app, ko) {
        //Note: This module exports an object.
        //That means that every module that "requires" it will get the same object instance.
        //If you wish to be able to create multiple instances, instead export a function.
        //See the "welcome" module for an example of function export.

    return {

        };
    });

back.html:

<section>
    <script language="javascript">
        window.location.replace('/Project');
    </script>
</section>

Any ideas/explanations? Any advice on what to try to debug further is appreciated!

Upvotes: 1

Views: 2078

Answers (1)

Nathan Fisher
Nathan Fisher

Reputation: 7941

then is usually associated with a promises library like Q.js. It is basically saying run a function asynchronously THEN run the function passed in. The error you are experiencing will because the function that is being run does not return a promise or returns something else or possibly nothing.

Looking at the Back.js file you provided, it will need to have an activate function at a minimum for durandal to load the page correctly, which I think will be your main problem.

define(['plugins/http', 'durandal/app', 'knockout'], function (http, app, ko) {
    //Note: This module exports an object.
    //That means that every module that "requires" it will get the same object instance.
    //If you wish to be able to create multiple instances, instead export a function.
    //See the "welcome" module for an example of function export.

    var vm = {
        activate: activate
    };

    return vm;

    function activate() {
        return true;
    }
});

Upvotes: 1

Related Questions