Angular 5 (IE11) Error: Uncaught (in promise): Error: Cannot match any routes
几天来,我在Angular 5中遇到了IE11的麻烦。我打开了polyfills:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import 'core-js/es6/symbol'; import 'core-js/es6/object'; import 'core-js/es7/object'; import 'core-js/es6/function'; import 'core-js/es6/parse-int'; import 'core-js/es6/parse-float'; import 'core-js/es6/number'; import 'core-js/es6/math'; import 'core-js/es6/string'; import 'core-js/es6/date'; import 'core-js/es6/array'; import 'core-js/es6/regexp'; import 'core-js/es6/map'; import 'core-js/es6/weak-map'; import 'core-js/es6/set'; |
并为IE设置元标记:
1 | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> |
使用ng serve启动项目时,一切都正常。但是,当我使用--prod选项构建项目时,应用程序无法在IE11中运行。 Firefox和Chrome正常运行。
控制台日志:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'gui/account' Error: Cannot match any routes. URL Segment: 'gui/account' at Anonymous function (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:401190) at e.prototype.error (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:386643) at e.prototype._error (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:7955) at e.prototype.error (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:7661) at e.prototype._error (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:7955) at e.prototype.error (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:7661) at e.prototype._error (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:7955) at e.prototype.error (http://localhost:8080/gui/main.d12ff1833b14b6308efb.bundle.js:1:7661) at e.prototype._error (http://localhost:8080/gui/main.d12ff1833 SCRIPT5011: Can't execute code from a freed script File: polyfills.6460c1711c3b9abc371d.bundle.js, Line: 1, Column: 69035 |
当我尝试调试它时,polyfills.bundle.js中出现一些错误:
IE11调试屏幕截图
非常感谢您的帮助。
我只有使用Angular 6和Spring boot的IE11遇到相同的问题
我使用自己的工厂解决了该问题,该工厂根据当前位置
1 2 3 4 | { provide: APP_BASE_HREF, useValue: window.location.pathname, } |
我还从
请参阅带有子文件夹相对基本路径的IE11路由问题
查看我的源代码
我终于找到了导致此问题的原因。我从Spring应用程序webapp / gui文件夹提供Angular应用程序。这导致路由器表现异常,解决方案是从
更改index.html中的基本href
1 | <base href="#/"> |
到
1 | <base href="/gui/"> |
这样,我的Angular Spring控制器会将链接http:// localhost:8080 / gui / account重定向到Angular index.html。然后,Angular路由器将选择此链接并重定向到/ account组件。
这可能与缺陷https://github.com/angular/angular/issues/18176有关。
我希望这也会对你们有帮助。