X Tutup
Skip to content

Commit 9dc1d6a

Browse files
committed
fix(code size): do not rely on Uri in BrowserDomAdapter
Closes #4182
1 parent e4f94f0 commit 9dc1d6a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

modules/angular2/src/core/dom/browser_adapter.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,12 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
426426
return window.location;
427427
}
428428

429-
getBaseHref() {
429+
String getBaseHref() {
430430
var href = getBaseElementHref();
431431
if (href == null) {
432432
return null;
433433
}
434-
var baseUri = Uri.parse(href);
435-
return baseUri.path[0] == '/' ? baseUri.path : ('/' + baseUri.path);
434+
return _relativePath(href);
436435
}
437436

438437
resetBaseElement() {
@@ -487,3 +486,14 @@ String getBaseElementHref() {
487486
}
488487
return baseElement.getAttribute('href');
489488
}
489+
490+
// based on urlUtils.js in AngularJS 1
491+
AnchorElement _urlParsingNode = null;
492+
String _relativePath(String url) {
493+
if (_urlParsingNode == null) {
494+
_urlParsingNode = new AnchorElement();
495+
}
496+
_urlParsingNode.href = url;
497+
var pathname = _urlParsingNode.pathname;
498+
return (pathname[0] == '/') ? pathname : '/${pathname}';
499+
}

0 commit comments

Comments
 (0)
X Tutup