2016-01-28 54 views
0

我是Durandal的新手,但熟悉mvc4。我试图移植一个现有的应用程序,大量使用淘汰赛到SPA框架。如何在Durandal中配置路径?

我已经能够得到标准视图/视图模型约定与此文章的信息工作:https://stackoverflow.com/a/15636715/1693081

我想把这个扩展到基于特征的结构,因为每个页面有多个可重用的组件,我想设置我的应用程序目录如下:

App 
| 
|--- Pages 
| | 
| |---Shell 
| | | 
| | |---Shell.chtml 
| | |---Shell.js 
| | |---web.config 
| | 
| |---Dashboard 
     | 
     |---Dashboard.chtml 
     |---Dashboard.js 
     |--web.config 

我认为这将是作为注释掉viewLocator.userConvention()一样简单,并增加了新的途径,但是,这将引发一个无法加载根模块异常。

从我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:

 routes.MapRoute(
      name: "Durandal Page Level Views", 
      url: "App/Pages/{viewFolder}/{viewName}.html", 
      defaults: new { controller = "DurandalView", action = "Get" } 
     ); 

我失去了一些东西明显? Durandal的文件表明,他们的默认设置对于大型应用程序来说并不是最好的,但是并没有给我一个关于如何解决这个问题的想法。

谢谢!

+0

在你的问题的帖子是关系到有人试图使用CSHTML文件。你是否也需要这样做,或者你使用html文件好吗? – Ryan

+0

我已经更新了我的场景和答案。 –

回答

0

我有这方面的工作。事实证明,放弃web.config会干扰在每个目录中加载js文件的能力。我最终将每个页面拆分为模型和查看模型文件夹。

| 
|---Pages 
    | 
    |---Shell 
     | 
     |---View 
     | | 
     | |---Shell.html 
     | |---web.config 
     | 
     |---ViewModel 
      | 
      |---Shell.js 
相关问题