0

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

4

1 回答 1

2

这是因为视图定位器的行为,默认情况下会在您描述的第一个结构中查找视图/视图模型。

您可以通过提供自己的视图定位器函数或useConvention()像这样调用来轻松更改此行为useConvention(modulesPath, viewsPath, areasPath)

于 2013-05-21T21:17:57.160 回答