使用Google AppEngine和Flask的角度路由



我在Google AppEngine上有一个应用程序,在后端使用Python3和Flask,在前端使用Angular。如果前端使用Angular路由导航到/welcome,则工作正常。但是,如果我点击浏览器刷新,它会显示404错误,因为后端当然不存在xxxx.appspot.com/welcome。有办法绕过这个吗?这是我的应用程序

runtime: python38
handlers:
- url: /rest/.*
script: auto
- url: /(.+)
static_files: dist/1
upload: dist/(.*)
- url: /
static_files: dist/index.html
upload: dist/index.html

我无法让评论中提供的建议发挥作用。应该有一个服务器端的修复程序,但似乎我应该做的一切都已经完成了。因此,我实现了一个符合我的目的的客户端解决方案。首先,我指定在url生成中使用哈希,app-routing.module.ts:中有以下部分

@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule],
bootstrap: [AppComponent]
})

这消除了404错误,但并没有达到预期的效果。因此,我在app.component.ts中捕获了一个刷新请求,构造函数中有以下代码:

router.events.subscribe((event) => {
if (event instanceof NavigationStart) {
if (!router.navigated) this.goHome();  // That is, user hit the refresh button
}
});

调用我自己的goHome()方法,该方法处理适当的导航。

最新更新