aurelia框架是否提供了检查视图是否存在的方法?
ViewLocator.prototype.convertOriginToViewUrl = (origin) => {
let device = 'mobile';
let moduleId = origin.moduleId.replace('.js', '').replace('.ts', '');
let deviceView = `${moduleId}-${device}.html`;
//check if view exist and return if so
if (ViewExist(deviceView)) {
return deviceView;
}
//return default view
return `${moduleId}.html`;
}
function ViewExist(view): boolean {
//check filessytem?
//check app-bundle?
//any available api in aurelia to check?
return false;
}我尝试过从aurelia-fetch-client使用HttpClient,但我猜是因为文件被捆绑到应用程序包中,所以这个选项是不可能的。
let http = new HttpClient();
let response = http.fetch('view-mobile.html');发布于 2018-03-12 18:28:34
您可以实现自己的视图定位器,并替换框架使用的视图定位器
您可以通过在DI容器中注入viewLocator来做到这一点
另请查看有关自定义约定http://aurelia.io/docs/fundamentals/app-configuration-and-startup#customizing-conventions的文档
https://stackoverflow.com/questions/45352141
复制相似问题