Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: add a viewUrl property to the routes #882

Closed
gordon-matt opened this issue Apr 23, 2018 · 3 comments
Closed

Request: add a viewUrl property to the routes #882

gordon-matt opened this issue Apr 23, 2018 · 3 comments

Comments

@gordon-matt
Copy link

gordon-matt commented Apr 23, 2018

As discussed in an email with @EisenbergEffect, could we please have a viewUrl property in the routes? At the moment it appears that Aurelia is simply taking the moduleId and appending a .js extension to find the model and an .html extension to find the view.

In order to use Razor routes, I make use of ViewLocator.prototype.convertOriginToViewUrl as follows:

ViewLocator.prototype.convertOriginToViewUrl = function (origin) {

    //console.log("origin: " + JSON.stringify(origin));
    var viewUrl = null;
    var idx = origin.moduleId.indexOf('aurelia-app');

    // The majority of views should be under /wwwroot/aurelia-app
    if (idx != -1) {
        viewUrl = origin.moduleId.substring(idx + 11).replace(".js", '');
    }
    // JSPM packages may need to load HTML files (example: aurelia-kendoui-bridge)
    // TODO: This is not perfect.. (what if the view we want to show is normal HTML, but not in jspm_packages folder?)
    else if (origin.moduleId.indexOf('jspm_packages') !== -1) {
        viewUrl = origin.moduleId.replace(".js", '.html');
    }
    else {
        // This is for any js files in top-level of /wwwroot directory (should point to HomeController).
        var split = origin.moduleId.split("/");
        viewUrl = split[split.length - 1].replace(".js", '');
    }

    console.log('View URL: ' + viewUrl);
    return viewUrl;
}

If you look at it carefully, you will see it’s not quite perfect. I would actually prefer to not have to do this at all.. we could have Aurelia still look for .html files by default, but if there’s a viewUrl property in the route definition, then use that instead.. That way, modules that are not being served by ASP .NET controllers and have actual HTML files (for example: aurelia-kendo-bridge and others) won’t be affected... and it will allow me to have the .js file location decoupled from the .html file location, so I can put them wherever I want and additionally, I can then use embedded javascript as well. I did that with Durandal by passing the embedded script path to the RequireJS config.. but I currently don’t see a way of doing this in Aurelia.. and I absolutely need embedded js files in my architecture in some cases.

@davismj
Copy link
Member

davismj commented Apr 23, 2018

@EisenbergEffect can you move this to router please?

@stsje
Copy link

stsje commented Apr 23, 2018

I'm not sure a new viewUrl property will be a good name when/if the new component property is implemented. aurelia/templating-router#75
At least consider the above PR before implementing viewUrl :)!

@EisenbergEffect
Copy link
Contributor

Issue moved to aurelia/router #590 via ZenHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants