0

How can I not to load any module or page when I start the durandal app?

I want to load the page content from server side programme (PHP & MySQL) into

<div id="applicationHost">..</div>

only then the durandal app will follow. is it possible?

index.html,

<!DOCTYPE html>
    <html>
        <head>
            <title>Durandal</title>
            <meta charset="utf-8" />
            <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.css" />
            <link rel="stylesheet" href="lib/bootstrap/css/bootstrap-responsive.css" />
            <link rel="stylesheet" href="lib/durandal/css/durandal.css" />
            <script src="lib/require/require.js" data-main="app/main"></script>
        </head>
        <body>
            <div>
               <a href="#/first">first</a>
                <a href="#/second">second</a>
                <a href="#/user/123">user 123</a> 
            </div>
            <div id="applicationHost">
                // load the page content from server side.
            </div>
        </body>
    </html>

shell.js

define(['plugins/router', 'durandal/system'], function (router, system) {
    return {
        router: router,
        activate: function () {

            router.makeRelative({moduleId: 'viewmodels'});

            router.map([
                /*
                { 
                    route: '', 
                    title:'Welcome', 
                    moduleId: '/first', 
                    nav: true 
                },
                */
                { 
                    route: 'first', 
                    title:'Welcome', 
                    moduleId: '/first', 
                    nav: true 
                },
                { 
                    route: 'second', 
                    moduleId: '/second', 
                    nav: true 
                },
                { 
                    route: 'user/:id', 
                    moduleId: '/second' 
                }
            ]);

            //builds an observable model from the 
            //mapping to bind your UI to
            router.buildNavigationModel();

            //sets up conventional mapping for 
            //unrecognized routes
            router.mapUnknownRoutes('viewmodels/not-found', 'not-found');

            system.log("shell started.");

            //return router.activate({ pushState: true });
            return router.activate();
        }
    };
});

I get an error for commenting out this from the route,

                { 
                    route: '', 
                    title:'Welcome', 
                    moduleId: '/first', 
                    nav: true 
                },

error,

system.js (line 80)
Error: Failed to load routed module (viewmodels/viewmodels/not-found). Details: Script error for: viewmodels/viewmodels/not-found http://requirejs.org/docs/errors.html#scripterror


exception = new Error(error);
Run
  • 54,938
  • 169
  • 450
  • 748
  • You could dump your server-side content into some hidden div and then use it as a view for your homepage module. But do you really have to? The beauty of spa is in complete depoupling of frontend and backend. I would suggest that you move all the static code to the frontend and progressively enhance with ajax as it loads. – Dziamid Oct 27 '14 at 06:22
  • I would agree with @Dziamid: I think you're using the wrong technology if you still have that kind of dependency on the server (particularly for simply starting up). Exceptions might be an application that provides for viewing and editing HTML templates, but even then, pulling that template out of a database using AJAX could obviate the need to depend on the web server. –  Oct 27 '14 at 15:45
  • Coincidentally, I just read an article that came across my Flipboard about LazoJS (http://radar.oreilly.com/2014/10/isomorphic-javascript-with-lazojs.html). Fascinating read, and it seemed to address your needs. I would very much be interested in your thoughts after you read the article. The article is modern, relevant, and addresses a real-world problem on a large scale. –  Oct 28 '14 at 00:25

0 Answers0