是否有可能在Java应用程序中将404重定向到Google App Engine标准中的index.html? [英] Is it possible to redirect 404 to index.html on Google App Engine Standard in a Java app?
问题描述
我试图在Google App Engine上部署一个带有Java后端的Angular 4应用程序(标准)。一切正常,除非我尝试重新加载页面。发生什么情况是要求例如myapp.com/some/page应该重定向到myapp.com/index.html,以便Angular应用程序进行响应。
据我所见,如果使用app.yaml配置文件,它可用于除Java以外的所有支持语言(使用appengine-web。 xml和web.xml)。
这可以通过appengine-web.xml来完成吗?以任何其他方式?
是的,您必须使用HashLocationStrategy而不是默认的PathLocationStrategy。
Angular的文档: https:/ /angular.io/guide/router#appendix-locationstrategy-and-browser-url-styles
基本上,您只需告诉RouterModule使用HashLocationStrategy在你的AppRoutingModule中:
@NgModule({
imports:[RouterModule.forRoot(routes,{useHash:true })],
exports:[RouterModule]
})
export class AppRoutingModule {
}
我希望它有帮助
I'm trying to deploy an Angular 4 app with a Java backend on Google App Engine (standard). Everything works fine except when I try to reload the page. What happens is that a request to e.g. myapp.com/some/page should be redirected to myapp.com/index.html for the Angular app to respond.
As far as I can see, this would be possible if using the app.yaml configuration file which is used for all supported languages except Java (which uses appengine-web.xml and web.xml).
Can this be done with appengine-web.xml? In any other way?
Yes you have to use the HashLocationStrategy instead of the default PathLocationStrategy.
Angular's documentation: https://angular.io/guide/router#appendix-locationstrategy-and-browser-url-styles
Basically, you just have to tell the RouterModule to use HashLocationStrategy in your AppRoutingModule:
@NgModule({
imports: [RouterModule.forRoot(routes, {useHash: true})],
exports: [RouterModule]
})
export class AppRoutingModule {
}
I hope it helps
这篇关于是否有可能在Java应用程序中将404重定向到Google App Engine标准中的index.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!