问题描述
我有一个与Durandal一起使用的小型SPA测试应用程序。
我也有非常有线的问题。
首先,我的文件夹结构是:
App
--durandal
--viewmodels
---- user.js
--views
---- user.html
--main.js
当结构是这样时,一切都很好。但是如果我创建类似
App
$ br $ b --durandal
--_ user
---- viewmodels的结构
------ user.js
----视图
------ user.html
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
我收到类似localhost / App / _users / viewmodels /users.html 404之类的错误。
I get error like localhost/App/_users/viewmodels/users.html 404 Not Found. And that happens after user.js are loaded by require.js.
我的main.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);
};
});
});
我认为这个问题与router.useConvention()有关。或使用viewLocator.useConvention();或
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?
谢谢
推荐答案
这是由于,默认情况下,它会在您描述的第一个结构中查找视图/视图模型。
This is because of the behavior of the view locator, which by defaults looks for views/viewmodels in the first structure you describe.
您可以通过提供自己的视图定位器函数或调用 useConvention()
这样的 useConvention(modulesPath,viewsPath,areaPath )
You can easily change this behavior by supplying your own view locator function, or by calling useConvention()
like this useConvention(modulesPath, viewsPath, areasPath)
这篇关于杜兰达路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!