Angular 5 (IE11) Error: Uncaught (in promise): Error: Cannot match any routes
Angular 5 (IE11) Error: Uncaught (in promise): Error: Cannot match any routes
我有几天在 Angular 5 中遇到 IE11 问题。我已经打开 polyfills:
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 设置元标记:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
当我使用 ng serve 启动项目时一切正常。但是当我使用 --prod 选项构建项目时,应用程序无法在 IE11 中运行。 Firefox 和 Chrome 工作正常。
控制台日志:
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 debug screenshot
非常感谢您的帮助。
我终于找到了导致这个问题的原因。我正在从 Spring 应用程序 webapp/gui 文件夹 中提供 Angular 应用程序。这导致路由器行为异常,解决方案是将 index.html 中的 base href 从
更改为
<base href="#/">
到
<base href="/gui/">
这样我的 Angular Spring 控制器会将 link http://localhost:8080/gui/account 重定向到 Angular index.html。然后 Angular 路由器将选择这个 link 并重定向到 /account 组件。
这可能与缺陷有关https://github.com/angular/angular/issues/18176。
我希望这对你们也有帮助。
我只在使用 Angular 6 和 Spring boot
的 IE11 上遇到了同样的问题
我使用自己的工厂根据当前位置提供 APP_BASE_HREF
令牌解决了问题 window.location.pathname
:
{
provide: APP_BASE_HREF,
useValue: window.location.pathname,
}
我还从 index.html
中删除了 <base href
> 标签,以保持简洁。
我有几天在 Angular 5 中遇到 IE11 问题。我已经打开 polyfills:
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 设置元标记:
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
当我使用 ng serve 启动项目时一切正常。但是当我使用 --prod 选项构建项目时,应用程序无法在 IE11 中运行。 Firefox 和 Chrome 工作正常。
控制台日志:
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 debug screenshot
非常感谢您的帮助。
我终于找到了导致这个问题的原因。我正在从 Spring 应用程序 webapp/gui 文件夹 中提供 Angular 应用程序。这导致路由器行为异常,解决方案是将 index.html 中的 base href 从
更改为<base href="#/">
到
<base href="/gui/">
这样我的 Angular Spring 控制器会将 link http://localhost:8080/gui/account 重定向到 Angular index.html。然后 Angular 路由器将选择这个 link 并重定向到 /account 组件。
这可能与缺陷有关https://github.com/angular/angular/issues/18176。
我希望这对你们也有帮助。
我只在使用 Angular 6 和 Spring boot
的 IE11 上遇到了同样的问题我使用自己的工厂根据当前位置提供 APP_BASE_HREF
令牌解决了问题 window.location.pathname
:
{
provide: APP_BASE_HREF,
useValue: window.location.pathname,
}
我还从 index.html
中删除了 <base href
> 标签,以保持简洁。