diff --git a/src/composition-engine.js b/src/composition-engine.js index d5d82a87..96018cdb 100644 --- a/src/composition-engine.js +++ b/src/composition-engine.js @@ -1,3 +1,4 @@ +import {Origin} from 'aurelia-metadata'; import {ViewStrategy, UseView} from './view-strategy'; import {ResourceCoordinator} from './resource-coordinator'; import {ViewEngine} from './view-engine'; @@ -36,14 +37,22 @@ export class CompositionEngine { viewModel = instruction.viewModel; return this.activate(instruction).then(() => { - var doneLoading; + var doneLoading, viewStrategyFromViewModel, origin; if('getViewStrategy' in viewModel && !instruction.view){ + viewStrategyFromViewModel = true; instruction.view = ViewStrategy.normalize(viewModel.getViewStrategy()); } - if(instruction.view && instruction.viewResources){ - instruction.view.makeRelativeTo(instruction.viewResources.viewUrl); + if (instruction.view) { + if(viewStrategyFromViewModel){ + origin = Origin.get(viewModel.constructor); + if(origin){ + instruction.view.makeRelativeTo(origin.moduleId); + } + }else if(instruction.viewResources){ + instruction.view.makeRelativeTo(instruction.viewResources.viewUrl); + } } if(viewModelInfo){ @@ -86,6 +95,10 @@ export class CompositionEngine { return this.createBehaviorAndSwap(instruction); } }else if(instruction.view){ + if(instruction.viewResources){ + instruction.view.makeRelativeTo(instruction.viewResources.viewUrl); + } + return instruction.view.loadViewFactory(this.viewEngine).then(viewFactory => { result = viewFactory.create(childContainer, instruction.executionContext); instruction.viewSlot.swap(result); diff --git a/src/view-strategy.js b/src/view-strategy.js index 92875f3c..3aa4ea1d 100644 --- a/src/view-strategy.js +++ b/src/view-strategy.js @@ -50,6 +50,10 @@ export class UseView extends ViewStrategy { } loadViewFactory(viewEngine, options){ + if(!this.absolutePath && this.moduleId){ + this.absolutePath = relativeToFile(this.path, this.moduleId); + } + return viewEngine.loadViewFactory(this.absolutePath || this.path, options, this.moduleId); }