How do you configure pathing in Durandal?

醉酒当歌 提交于 2020-01-17 05:08:10

问题


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.

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

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.

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');
});

from my Routeconfig.cs:

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

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.

Thanks!


回答1:


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


来源:https://stackoverflow.com/questions/35056736/how-do-you-configure-pathing-in-durandal

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