Heroku阻止直接访问Angular中的子路由

时间:2020-08-18 11:59:02

标签: angular heroku routes

我使用URL mean-app.herokuapp.com将MEAN堆栈应用程序部署到了Heroku。在本地测试环境中,我可以直接访问http:// localhost:4200 / login页面,而无需通过http:// localhost:4200 /导航进行登录。但是,我不能在生产中做同样的事情。当我尝试直接访问https://mean-app.herokuapp.com/login时,出现错误消息:

Failed to load resource: the server responded with a status of 404 (Not Found)

在部署到Heroku之后如何直接访问已部署的Web应用程序的子路由?

1 个答案:

答案 0 :(得分:0)

此链接(https://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml)准确地描述了我所遇到的问题,并且为该问题提供了一个通用的解决方案,但对于我的情况而言不够具体。

这里(https://github.com/angular/angular-cli/issues/2885)实际上有一个解决方案,您要做的就是更改

RouterModule.forRoot(appRoutes);

进入

RouterModule.forRoot(appRoutes, {useHash: true});