Durandal routing issue

為{幸葍}努か 提交于 2019-12-12 05:48:36

问题


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


回答1:


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)



来源:https://stackoverflow.com/questions/16677596/durandal-routing-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!