Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have small SPA test app with Durandal. Also I have very wired issue. First, my folder structure is:
App
--durandal
--viewmodels
----user.js
--views
----user.html
--main.js
And when structure is like that all works just fine. But if I create structure like
App
--durandal
--_user
----viewmodels
------user.js
----views
------user.html

I get error like localhost/App/_users/viewmodels/users.html 404 Not Found. And that happens after user.js are loaded by require.js.

my main.js looks like

require.config({
   paths: { "text": "../durandal/amd/text" }
});

define(function (require) {
   var system = require('../durandal/system'),
      app = require('../durandal/app'),
      router = require('../durandal/plugins/router'),
      viewLocator = require('../durandal/viewLocator'),
      logger = require('../logger');

   system.debug(true);

   app.start().then(function () {
      // route will use conventions for modules
      // assuming viewmodels/views folder structure
      router.useConvention();


      // When finding a module, replace the viewmodel string 
      // with view to find it partner view.
      // [viewmodel]s/sessions --> [view]s/sessions.html
      // Otherwise you can pass paths for modules, views, partials
      // Defaults to viewmodels/views/views. 
      viewLocator.useConvention();

      app.setRoot('viewmodels/shell');

      // override bad route behavior to write to 
      // console log and show error toast
      router.handleInvalidRoute = function (route, params) {
         logger.logError('No route found', route, 'main', true);
      };
   });
});

I assume that this issue has something with router.useConvention(); or with viewLocator.useConvention(); but simple can't find any reason for that kind of behavior.

Any help, suggestion, idea how to solve this?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is because of the behavior of the view locator, which by defaults looks for views/viewmodels in the first structure you describe.

You can easily change this behavior by supplying your own view locator function, or by calling useConvention() like this useConvention(modulesPath, viewsPath, areasPath)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...