diff --git a/modules/angular2/src/dom/browser_adapter.dart b/modules/angular2/src/dom/browser_adapter.dart index f85414530b..48161b9f1b 100644 --- a/modules/angular2/src/dom/browser_adapter.dart +++ b/modules/angular2/src/dom/browser_adapter.dart @@ -318,4 +318,9 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter { getLocation() { return window.location; } + getBaseHref() { + var uri = document.baseUri; + var baseUri = Uri.parse(uri); + return baseUri.path; + } } diff --git a/modules/angular2/src/dom/browser_adapter.es6 b/modules/angular2/src/dom/browser_adapter.es6 index 4990b95cc2..223aa872e8 100644 --- a/modules/angular2/src/dom/browser_adapter.es6 +++ b/modules/angular2/src/dom/browser_adapter.es6 @@ -381,4 +381,17 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { getLocation() { return window.location; } + getBaseHref() { + return relativePath(document.baseURI); + } +} + +// based on urlUtils.js in AngularJS 1 +var urlParsingNode = null; +function relativePath(url) { + if (isBlank(urlParsingNode)) { + urlParsingNode = document.createElement("a"); + } + urlParsingNode.setAttribute('href', url); + return (urlParsingNode.pathname.charAt(0) === '/') ? urlParsingNode.pathname : '/' + urlParsingNode.pathname; } diff --git a/modules/angular2/src/dom/dom_adapter.js b/modules/angular2/src/dom/dom_adapter.js index cff55c4b6b..2c2662e375 100644 --- a/modules/angular2/src/dom/dom_adapter.js +++ b/modules/angular2/src/dom/dom_adapter.js @@ -292,4 +292,7 @@ export class DomAdapter { getLocation() { throw _abstract(); } + getBaseHref() { + throw _abstract(); + } } diff --git a/modules/angular2/src/dom/html_adapter.dart b/modules/angular2/src/dom/html_adapter.dart index 611e50239c..e3e309a3fb 100644 --- a/modules/angular2/src/dom/html_adapter.dart +++ b/modules/angular2/src/dom/html_adapter.dart @@ -297,4 +297,7 @@ class Html5LibDomAdapter implements DomAdapter { getLocation() { throw 'not implemented'; } + getBaseHref() { + throw 'not implemented'; + } }