Using `window.location.hash.includes` throws “Object doesn't support property or method 'includes'” in IE11
According to the MDN reference page, includes
is not supported on Internet Explorer. The simplest alternative is to use indexOf
, like this:
if(window.location.hash.indexOf("?") >= 0) {
...
}
IE11 does implement String.prototype.includes so why not using the official Polyfill?
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
Source: polyfill source
Adding import 'core-js/es7/array';
to my polyfill.ts
fixed the issue for me.