python - Elastic Beanstalk 上的单页应用程序的路由问题
问题描述
使用 Flask 作为 Web 服务器,使用 Angular 作为我在 /static 目录中的 SPA。我在我的 Flask 应用程序上实现了一个包罗万象的端点,以尝试解决用户在404
刷新页面时得到的问题,但它并没有解决问题。有谁知道如何解决这一问题?
包罗万象的样子:
@application.route('/', defaults={'path': ''})
@application.route('/static/<path:path>')
def main(path):
return render_template('index.html')
如果抛出 404,我还实现了重定向,但这也无济于事:
@application.errorhandler(Exception)
@cross_origin()
def main_404(*args, **kwargs):
logger.info("Routing passed to web application...")
return render_template('index.html')
解决方案
如果要捕获错误,请尝试使用错误处理程序:
@application.errorhandler(404)
def page_not_found(error):
app.logger.error('Page not found: %s', (request.path))
return render_template('404.html'), 404
推荐阅读
- excel - 在 Excel 中输入某个值时如何自动填充数据?
- python - 网页抓取/Beautifulsoup/有时无回报?
- c++ - 我的代码中是否存在内存泄漏?用 valgrind 检查
- excel - 使用单独的库存和发行表在谷歌表中维护库存表
- php - 在 PHP Navbar 中添加下拉菜单
- android - 构建一个非常简单的移动应用程序(没有移动开发经验)
- routing - 在 Sapper 中作为模态路由
- kotlin - 将多个 Kotlin 流合并到一个列表中,而无需等待第一个值
- postgresql - Postgresql 触发器行为怪异
- excel - 从 .txt 文件中提取特定值并放入 excel