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

Add support for routable engines #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions addon/helpers/href-to-external.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
});
12 changes: 11 additions & 1 deletion addon/helpers/href-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
1 change: 1 addition & 0 deletions app/helpers/href-to-external.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, hrefToExternal } from 'ember-href-to/helpers/href-to-external';