Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask route for AngularJS with HTML5 URL mode

I have an AngularJS app being served via Flask. I am using the HTML5 routing mode and thus need to redirect several URLs to the client app. I'm not sure how to do the wildcard matching needing to do this correctly. Currently I just match multiple levels of path like this:

@app.route('/ui/')
def ui():
    return app.send_static_file('index.html')
@app.route('/ui/<path>')
def ui(path):
    return app.send_static_file('index.html')
@app.route('/ui/<path>/<path2>')
def ui(path,path2):
    return app.send_static_file('index.html')

Obviously I don't like this and would like to just have one route (everything starting with ui/).

like image 669
edA-qa mort-ora-y Avatar asked May 14 '13 09:05

edA-qa mort-ora-y


1 Answers

The path url converter can do this for you:

@app.route('/ui/<path:p>')
def ui(p):
    return app.send_static_file('index.html')
like image 168
DazWorrall Avatar answered Oct 14 '22 21:10

DazWorrall