我有Durandal的小型SPA测试应用。 另外我有非常有线的问题。 首先,我的文件夹结构是:
应用
--durandal
--viewmodels
---- user.js的
--views
---- user.html
- 主。 js
而当结构就像所有的工作都很好。但是,如果我创建结构类似
应用
--durandal
--_用户
----的ViewModels
------ user.js的
----意见
---- --user.html
Durandal路由问题
我得到像localhost/App/_users/viewmodels /users.html 404 Not Found错误。在user.js被require.js加载后会发生这种情况。
我main.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('_ users/viewmodels','_users/views')放在那里,那么app.setRoot('viewmodels/shell');如果我把.useConvention('viewmodels','views');,然后再次获取本地主机/应用程序,然后我得到错误404找不到 - 本地主机/应用程序/ _users/viewmodels/shell.html“ /_users/viewmodels/users.html 404 Not Found。因此,这是非常令人困惑的,如果我将user.html从视图文件夹移动到查看文件夹,然后是所有分支,但会得到稍微不同的调试消息 – dewebeloper
使用'useConvention('_ users /这个应该可以工作,记住,任何时候当你引用一个视图模型时,你仍然必须使用*视图模型,而不是视图模型的视图模型,完整的* moduleid路径,这是从App文件夹的路径。 – Tyrsius
谢谢,但仍然不起作用。当我应用您的建议,然后我得到“NetworkError:404未找到 - 本地主机/应用程序/ _users/_users/viewmodels /外壳.js“ – dewebeloper