1

I'm trying to get Aurelia to use a Razor view(.cshtml) instead of regular .html and the proposed way to do it is to override convertOriginToViewUrl with the appropriate code. In my case a route to the action that returns PartialViews.

import {ViewLocator} from 'aurelia-framework';

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

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

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

There are some posts about the same subject, Customizing Aurelia to use .cshtml, but it doesn't seem to work for me.

The controller just returns a PartialView which works when you access the route through your browser but when Aurelia tries to use the rout /template?view=app it seems to be trying to access it throught ".//template?view=app" which does not exist.

What am I missing here? Am I supposed to build a whole new ViewLocator? Is it a webpack issue?

Community
  • 1
  • 1
Peter Wikström
  • 261
  • 4
  • 11

1 Answers1

0

If you are using Webpack, that could be part of your problem. Webpack is expecting your views to be pre-bundled. It's not expecting them to be dynamically loaded from the server.

EisenbergEffect
  • 3,989
  • 22
  • 26
  • Any ideas how to proceed? Is the problem in the Aurelia webpack plugin? Any contacts there that can help me? – Peter Wikström May 09 '17 at 06:02
  • It's not in the plugin per se. It's that this scenario requires webpack to dynamically load certain resources. So, they aren't "packed" ahead of time, which is the primary way that webpack works. I'm not a webpack expert myself, so I couldn't tell you if there's some sort of special webpack plugin that allows dynamic loading of the html at runtime. You might need to use something other than webpack. I'm not sure though. – EisenbergEffect May 10 '17 at 06:40
  • Most people who have done this in the past have used either require.js or system.js. Those are dynamic loaders that have the ability to handle this scenario normally. I don't know if webpack handles this or not. – EisenbergEffect May 10 '17 at 06:41