杜兰达尔路由问题



我有杜兰达尔的小型SPA测试应用程序。我也有非常有线的问题。首先,我的文件夹结构是:
应用
--杜兰达尔
--viewmodels
----user.js
--视图
----user.html
--主.js
当结构像这样时,一切都很好。但是如果我创建像
这样的结构应用程序
--杜兰达尔
--_user
----视图模型
------user.js
----视图
------user.html

我收到错误,例如本地主机/应用程序/_users/视图模型/用户.html 404 未找到。这发生在用户.js被require.js加载之后。

我的主.js看起来像

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);
      };
   });
});

我假设这个问题与router.useConvention((有关;或viewLocator.useConvention((有关;但简单找不到这种行为的任何原因。

任何帮助,建议,知道如何解决这个问题?

谢谢

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

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

最新更新