fix(browser_adapter.ts): baseElement.getAttribute
currently throwing an error ```error Error during instantiation of LocationStrategy! (RouterLink -> Router -> Location -> LocationStrategy). ORIGINAL ERROR: TypeError: baseElement.attr is not a function ``` Closes #3214
This commit is contained in:
parent
52da220016
commit
235dec26fc
|
@ -423,7 +423,11 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
return null;
|
||||
}
|
||||
var baseUri = Uri.parse(href);
|
||||
return baseUri.path;
|
||||
return baseUri.path[0] == '/' ? baseUri.path : ('/' + baseUri.path);
|
||||
}
|
||||
|
||||
resetBaseElement() {
|
||||
baseElement = null;
|
||||
}
|
||||
|
||||
String getUserAgent() {
|
||||
|
|
|
@ -297,6 +297,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
}
|
||||
return relativePath(href);
|
||||
}
|
||||
resetBaseElement(): void { baseElement = null; }
|
||||
getUserAgent(): string { return window.navigator.userAgent; }
|
||||
setData(element, name: string, value: string) { element.dataset[name] = value; }
|
||||
getData(element, name: string): string { return element.dataset[name]; }
|
||||
|
@ -313,7 +314,7 @@ function getBaseElementHref(): string {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
return baseElement.attr('href');
|
||||
return baseElement.getAttribute('href');
|
||||
}
|
||||
|
||||
// based on urlUtils.js in AngularJS 1
|
||||
|
|
|
@ -127,6 +127,7 @@ export class DomAdapter {
|
|||
getHistory(): History { throw _abstract(); }
|
||||
getLocation(): Location { throw _abstract(); }
|
||||
getBaseHref(): string { throw _abstract(); }
|
||||
resetBaseElement(): void { throw _abstract(); }
|
||||
getUserAgent(): string { throw _abstract(); }
|
||||
setData(element, name: string, value: string) { throw _abstract(); }
|
||||
getData(element, name: string): string { throw _abstract(); }
|
||||
|
|
|
@ -400,6 +400,10 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
throw 'not implemented';
|
||||
}
|
||||
|
||||
resetBaseElement() {
|
||||
throw 'not implemented';
|
||||
}
|
||||
|
||||
String getUserAgent() {
|
||||
throw 'not implemented';
|
||||
}
|
||||
|
|
|
@ -532,6 +532,8 @@ export class Parse5DomAdapter extends DomAdapter {
|
|||
return this.defaultDoc().body;
|
||||
}
|
||||
}
|
||||
getBaseHref(): string { throw 'not implemented'; }
|
||||
resetBaseElement(): void { throw 'not implemented'; }
|
||||
getHistory(): History { throw 'not implemented'; }
|
||||
getLocation(): Location { throw 'not implemented'; }
|
||||
getUserAgent(): string { return "Fake user agent"; }
|
||||
|
|
|
@ -49,5 +49,42 @@ export function main() {
|
|||
expect(DOM.isElementNode(secondChild)).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
if (DOM.supportsDOMEvents()) {
|
||||
describe('getBaseHref', () => {
|
||||
beforeEach(() => DOM.resetBaseElement());
|
||||
|
||||
it('should return null if base element is absent',
|
||||
() => { expect(DOM.getBaseHref()).toBeNull(); });
|
||||
|
||||
it('should return the value of the base element', () => {
|
||||
var baseEl = DOM.createElement('base');
|
||||
DOM.setAttribute(baseEl, 'href', '/drop/bass/connon/');
|
||||
var headEl = DOM.defaultDoc().head;
|
||||
DOM.appendChild(headEl, baseEl);
|
||||
|
||||
var baseHref = DOM.getBaseHref();
|
||||
DOM.removeChild(headEl, baseEl);
|
||||
DOM.resetBaseElement();
|
||||
|
||||
expect(baseHref).toEqual('/drop/bass/connon/');
|
||||
});
|
||||
|
||||
it('should return a relative url', () => {
|
||||
var baseEl = DOM.createElement('base');
|
||||
DOM.setAttribute(baseEl, 'href', 'base');
|
||||
var headEl = DOM.defaultDoc().head;
|
||||
DOM.appendChild(headEl, baseEl);
|
||||
|
||||
var baseHref = DOM.getBaseHref();
|
||||
DOM.removeChild(headEl, baseEl);
|
||||
DOM.resetBaseElement();
|
||||
|
||||
expect(baseHref).toEqual('/base');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue