I have an application with an AngularJS frontend and a Flask backend.
I have the following routes in Flask to send all requests to the index.html file (as well as some routes for API routes):
@app.route('/')
def home():
return render_template('index.html')
@app.route('/api/colours')
def colours():
...
@app.route('/<path:page>')
def fallback(page):
return redirect(url_for('home'))
I'm then using the Angular StateProvider for the client-side routing:
$stateProvider
.state('home', {
url: '/',
templateUrl: 'static/templates/home.html'
})
.state('contact', {
url: '/contact',
templateUrl: 'static/templates/contact.html'
});
This works great if I start at the root of my website and click a link to take me to the contact page. However, if I want to go to straight to the contact page by typing in mysite.com/contact it redirects the homepage. Which is expected.
How can I allow it go to the client side route if it's available, else redirect to home page?