如何在Angular应用中添加URL Polyfill以兼容IE11(适配angular2-jwt)
Hey fellow dev, I ran into the exact same problem when getting angular2-jwt up and running in IE11 a while back. Let me walk you through the concrete steps to add the required URL polyfill:
First, install the URL polyfill package
Head to your project root directory and run this command to install the dependency:npm install url-polyfill --saveAdd the polyfill to your Angular project's polyfills file
Locate thesrc/polyfills.tsfile in your Angular project (this is where all browser compatibility polyfills live). At the bottom of this file, add the following line:import 'url-polyfill';This will load the URL polyfill specifically for older browsers like IE11, which doesn't natively support the modern URL API that angular2-jwt relies on.
Test in IE11
Fire up your Angular app and test the angular2-jwt functionality in IE11. Any errors related toURL is undefinedor missing URL methods should now be resolved, since the polyfill provides the necessary implementation for IE11 to handle those operations.
A quick extra tip: If you're still hitting other IE11 compatibility issues, check the polyfills.ts file for other commented-out polyfills that Angular provides out of the box—you might need to uncomment some (like Promise polyfills) depending on your app's other dependencies.
内容的提问来源于stack exchange,提问作者Nehal Damania

