Aurelia中的自定义视图位置 [英] Custom view location in Aurelia
问题描述
我正在尝试让Aurelia使用Razor视图(.cshtml)而不是常规.html,建议的实现方法是使用适当的代码重写convertOriginToViewUrl.在我的情况下,返回返回PartialViews的动作的路线.
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());
}
有一些关于同一主题的帖子,自定义Aurelia以使用.cshtml ,但它似乎对我不起作用.
There are some posts about the same subject, Customizing Aurelia to use .cshtml, but it doesn't seem to work for me.
控制器只是返回一个PartialView,当您通过浏览器访问路由时,该函数会起作用,但是当Aurelia尝试使用rout/template?view = app时,似乎正在尝试通过".//template?view=应用"".
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.
我在这里想念什么? 我应该建立一个全新的ViewLocator吗? 这是一个webpack问题吗?
What am I missing here? Am I supposed to build a whole new ViewLocator? Is it a webpack issue?
推荐答案
如果您使用的是Webpack,则可能是问题的一部分. Webpack希望您的视图被预先捆绑.并不希望它们从服务器动态加载.
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.
这篇关于Aurelia中的自定义视图位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!