在/static目录中使用Flask作为web服务器,使用Angular作为我的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