Aurelia to return alternative view for viewmodule only if the view exist

Viewed 127

Do the aurelia framework provide a way to check whether a view exists?

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;

}

I've tried to use HttpClient from aurelia-fetch-client, but I guess because of the bundling of the files into app-bundle this option is not possible.

let http = new HttpClient();
let response = http.fetch('view-mobile.html');
1 Answers
Related