Angular - 构建后未处理的导航错误 [英] Angular - Unhandled Navigation Error after building

查看:19
本文介绍了Angular - 构建后未处理的导航错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下命令构建了一个带有 2 个路由的简单 angular 应用程序:

ng build --aot --prod --base-href ./

然后我打开位于 dist 文件夹中的 index.html 文件,应用程序运行但路由不起作用,我在控制台上收到以下警告:

希望能很好地解释我的问题.提前致谢.

解决方案

使用 Angular 路由引擎将迫使您将应用托管在某个服务器上(例如 IIS, NodeJS 等)

一个没有路由的简单 Angular 应用程序可以在不托管在服务器上的情况下运行.

来自 Angular 文档:

<块引用>

Angular 应用程序非常适合使用简单的静态 HTML 服务器进行服务.您不需要服务器端引擎来动态组合应用程序页面,因为 Angular 在客户端完成.

I have built a simple angular app with 2 routes through the following command:

ng build --aot --prod --base-href ./

Then i open the index.html file located in the dist folder and the app runs but the the routes don't work and i get the following warning on console:

Hope to have explained my question well. Thanks in advance.

解决方案

Using Angular routing engine will force you to host your app in some server (e.g. IIS, NodeJS etc.)

A simple angular app without routes can run without hosting it on a server.

From Angular docs:

Angular apps are perfect candidates for serving with a simple static HTML server. You don't need a server-side engine to dynamically compose application pages because Angular does that on the client-side.

If the app uses the Angular router, you must configure the server to return the application's host page (index.html) when asked for a file that it does not have.

这篇关于Angular - 构建后未处理的导航错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆