diff --git a/addon/helpers/href-to-external.js b/addon/helpers/href-to-external.js new file mode 100644 index 0000000..b5f67ff --- /dev/null +++ b/addon/helpers/href-to-external.js @@ -0,0 +1,22 @@ +import Helper from '@ember/component/helper'; +import { getOwner } from '@ember/application'; +import { getHrefFromOwner } from './href-to'; + +function hrefToExternal(context, targetRouteName, ...rest) { + const owner = getOwner(context); + + if(owner.mountPoint) { + targetRouteName = owner._getExternalRoute(targetRouteName); + } + return getHrefFromOwner(owner, targetRouteName, ...rest); +} + +export default Helper.extend({ + compute([targetRouteName, ...rest], namedArgs) { + if(namedArgs.params) { + return hrefToExternal(this, ...namedArgs.params); + } else { + return hrefToExternal(this, targetRouteName, ...rest); + } + } +}); diff --git a/addon/helpers/href-to.js b/addon/helpers/href-to.js index aa0d354..11aa057 100644 --- a/addon/helpers/href-to.js +++ b/addon/helpers/href-to.js @@ -2,7 +2,17 @@ import Helper from "@ember/component/helper"; import { getOwner } from "@ember/application"; export function hrefTo(context, params) { - let routing = getOwner(context).lookup("service:-routing"); + let owner = getOwner(context); + let ownerIsEngine = Boolean(owner.mountPoint) + + if (ownerIsEngine && targetRouteName !== 'application') { + targetRouteName = `${owner.mountPoint}.${targetRouteName}`; + } + return getHrefFromOwner(owner, params); +} + +export function getHrefFromOwner(owner, params) { + let routing = owner.lookup("service:-routing"); return routing.generateURL(...getParamsForGenerateURL(params)); } diff --git a/app/helpers/href-to-external.js b/app/helpers/href-to-external.js new file mode 100644 index 0000000..9d99b53 --- /dev/null +++ b/app/helpers/href-to-external.js @@ -0,0 +1 @@ +export { default, hrefToExternal } from 'ember-href-to/helpers/href-to-external';