Catch all routes for Flask

I am using Flask with React. I would like to create to catch the whole route looking like something like this (although this does not work):

@app.route('*') def get(): return render_template('index.html') 

Since my application will use React and it uses index.html to mount my React components, I would like every route request to point to my index.html page in templates. Is there a way to do this (or use redirection in the best way)?

+5
source share
1 answer

You can follow this guide: http://flask.pocoo.org/snippets/57/

 from flask import Flask app = Flask(__name__) @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def catch_all(path): return 'You want path: %s' % path if __name__ == '__main__': app.run() 
+6
source

Source: https://habr.com/ru/post/1271021/


All Articles