Custom view location in Aurelia

北城以北 提交于 2019-12-11 07:27:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/43044527/custom-view-location-in-aurelia

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