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

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

问题描述

我通过以下命令构建了具有2条路线的简单角度应用程序:

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

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

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

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.

推荐答案

使用Angular路由引擎将迫使您将应用托管在某些服务器上(例如

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.

来自角度文档:

Angular应用程序非常适合与简单的静态HTML服务器一起使用.您不需要服务器端引擎来动态编写应用程序页面,因为Angular会在客户端进行操作.

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.

如果该应用程序使用Angular路由器,则必须配置服务器,以在系统询问该应用程序没有的文件时返回该应用程序的宿主页(index.html).

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天全站免登陆