angular 2、如何在使用 http-server 构建和服务应用程序时访问深层链接?
angular 2, How to access deep links when building and serving app with http-server?
我有一个我想提供的应用程序,它运行良好,直到有人想要访问深度 link 并且他们收到 404。
当运行ning angular-cli命令ng serve
我用deep links没问题
但是我不能在本地环境之外使用 angular-cli 命令。
但是当我 运行 ng build
然后 http-server ./dist
(server) 我可以访问 url localhost:8080
并且我的登录页面显示向上。
我尝试访问深度 link localhost:8080/page
我返回 404。
有人可以建议如何解决这个问题吗?
我不确定这个特定的 http-server
如何处理 HTML5 路由 。但是,像 nginx
这样的老式服务器可以配置为按照您想要的方式提供 URL。
同样值得注意的是,您的 index.html
.
中必须包含 base-href
元素 set up properly
例如。在 nginx
的情况下,有 an option 称为 try_files
。它会尝试解析所有给定的选项,直到成功。
Angular 2's HTML5 routes can be resolved with: try_files $uri$args $uri$args/ index.html;
.
我有一个我想提供的应用程序,它运行良好,直到有人想要访问深度 link 并且他们收到 404。
当运行ning angular-cli命令ng serve
我用deep links没问题
但是我不能在本地环境之外使用 angular-cli 命令。
但是当我 运行 ng build
然后 http-server ./dist
(server) 我可以访问 url localhost:8080
并且我的登录页面显示向上。
我尝试访问深度 link localhost:8080/page
我返回 404。
有人可以建议如何解决这个问题吗?
我不确定这个特定的 http-server
如何处理 HTML5 路由 。但是,像 nginx
这样的老式服务器可以配置为按照您想要的方式提供 URL。
同样值得注意的是,您的 index.html
.
base-href
元素 set up properly
例如。在 nginx
的情况下,有 an option 称为 try_files
。它会尝试解析所有给定的选项,直到成功。
Angular 2's HTML5 routes can be resolved with: try_files $uri$args $uri$args/ index.html;
.