您如何在Durandal中配置路径? [英] How do you configure pathing in Durandal?
问题描述
我是Durandal的新手,但熟悉mvc4.我正在尝试将大量使用基因剔除的现有应用程序移植到SPA框架.
I'm a novice at Durandal but familiar with mvc4. I'm attempting to port an existing application that heavily uses knockout to a SPA framework.
我已经获得了使用以下信息的标准View/ViewModel约定: https://stackoverflow. com/a/15636715/1693081
I've been able to get the standard View / ViewModel convention working with the information from this post: https://stackoverflow.com/a/15636715/1693081
我想将此扩展到基于功能的结构,因为每个页面都有多个可重用的组件,我想按如下所示设置应用程序目录:
I'd like to extend this to a feature based structure because each page has multiple reusable components, I'd like to set up my application directory as follows:
App
|
|--- Pages
| |
| |---Shell
| | |
| | |---Shell.chtml
| | |---Shell.js
| | |---web.config
| |
| |---Dashboard
|
|---Dashboard.chtml
|---Dashboard.js
|--web.config
我认为这就像注释掉viewLocator.userConvention()并添加一条新路由一样简单,但这会导致无法加载根模块异常.
I thought it would be as simple as commenting out viewLocator.userConvention() and added a new route but this throws a failed to load root module exception.
来自我的main.js:
from my main.js:
app.start().then(function () {
//Replace 'viewmodels' in the moduleId with 'views' to locate the view.
//Look for partial views in a 'views' folder in the root.
//viewLocator.useConvention();
//Show the app by setting the root view model for our application with a transition.
app.setRoot('pages/shell/shell', 'entrance');
});
来自我的Routeconfig.cs:
from my Routeconfig.cs:
routes.MapRoute(
name: "Durandal Page Level Views",
url: "App/Pages/{viewFolder}/{viewName}.html",
defaults: new { controller = "DurandalView", action = "Get" }
);
我缺少明显的东西吗? Durandal的文档建议它们的默认值并不是大型应用程序的最佳选择,但是对于如何立即解决问题并没有给我一个思路.
Am I missing something obvious? The documentation for Durandal suggests that their defaults aren't best for a large application but doesn't give me an idea as to how to solve it out of the box.
谢谢!
推荐答案
我为此进行了解决.事实证明,删除web.config会干扰在每个目录中加载js文件的能力.我最终将每个页面分成模型和视图模型文件夹.
I had a work around for this. It turns out that dropping the web.config interferes with the ability to load the js files in each directory. I ended up splitting each page into model and view model folders.
|
|---Pages
|
|---Shell
|
|---View
| |
| |---Shell.html
| |---web.config
|
|---ViewModel
|
|---Shell.js
这篇关于您如何在Durandal中配置路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!