1

I'm trying to get my app to use server-side templates(.cshtml) and have tried the recommended approach of overriding the ViewLocator.prototype.convertOriginToViewUrl.

Unfortunately it doesn't seem to work with webpack, as hinted by @EisenbergEffect. on my previous question

I have a route that returns html and I want to use that as my view.

Example here in ASP.NET MVC

    public ActionResult Template(string view)
    {
        return View(string.Format("~/Views/Shared/ClientTemplates/{0}.cshtml", view));
    }

Aurelia code

    import {ViewLocator} from 'aurelia-framework';

    export function configure(aurelia) {
       aurelia.use
         .standardConfiguration()
         .developmentLogging();

        ViewLocator.prototype.convertOriginToViewUrl = (origin) => {
          return "/common/template?view=" + origin.moduleId;
        };

        aurelia.start().then(a => a.setRoot());
     }

Result Error: Cannot find module './/common/template?view=app'.

Running the route /common/template?view=app in a browser returns, as expected, the markup that resides in the app.cshtml

How can I configure webpack + aurelia to use server-side templates?

Community
  • 1
  • 1
Peter Wikström
  • 261
  • 4
  • 11
  • I know that my comment doesn't help anything with your question, but why you want to render your views with asp.net? What are the benefits? – Fabio May 09 '17 at 12:28
  • You can check this question, http://stackoverflow.com/questions/37870145/customizing-aurelia-to-use-cshtml – jmvtrinidad May 10 '17 at 04:45
  • @FabioLuz Soemexamples, different view structure depending on logged in user, the usage of .resx resources and so on... – Peter Wikström May 10 '17 at 08:10
  • @janmvtrinidad That doesn't work when you use webpack, – Peter Wikström May 10 '17 at 08:11
  • @PeterWikström I see... Well, you could do all of this only using aurelia, which would be a lot faster. This doesn't answer your question but I think you could give it a try – Fabio May 10 '17 at 12:38
  • Thanks, I have a pretty good idea how to do it with pure Aurelia code but if you have a project with a lot of legacy code it would be nice to just reuse the existing resources,... – Peter Wikström May 15 '17 at 15:42
  • @PeterWikström, did you get this working? Read somewhere that it may be possible to write a dynamic rest loader for webpack but not found anything yet. – LunchBaron Dec 22 '17 at 11:32
  • @LunchBaron nope, I haven't found any solution for this. I will check out the dynamic rest loader stuff – Peter Wikström Dec 25 '17 at 16:43

0 Answers0