Aurelia returns an alternate view for viewmodule only if the view exists

Does the aurelia engine provide a way to check if 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 tried to use the HttpClient from aurelia-fetch-client, but I think due to bundling of files in the app bundle this parameter is not possible.

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

      

+3


source to share


1 answer


You can implement your own view locator and replace one structure using

https://github.com/aurelia/templating/blob/7693dbd65e59e428e4052922920145b76240f3cf/src/view-locator.js



You can do this by embedding your viewLocator in a DI container

Also check the docs on customizing conventions http://aurelia.io/docs/fundamentals/app-configuration-and-startup#customizing-conventions

0


source







All Articles