Hi, I have read your article on https://codeburst.io/full-stack-single-page-application-with-vue-js-and-flask-b1e036315532, and tried with your example, everythin is fine, frontend and backend are separated.
But some thing wrong with Blueprint, I solved these problems at the end. Say, the project structure is the same with the project flask-vue-spa
, now I make an additionally directory named vue
at the same directory, like following:
- app.py
- vue
-- frontend
-- dist
-- vue.py
Contents of vue.py is similar with app.py but the object vue
is the instance of Blueprint:
from flask import render_template, Blueprint
vue = Blueprint( 'vue', __name__, template_folder='dist', static_folder='dist/static' )
@vue.route( '/', defaults = { 'path': '' })
@vue.route( '/<path:path>' )
def index(path):
return render_template( "index.html" )
And the prefix for this blueprint is /vue
Then I had to modify two another files, one is /vue/frontend/config/index.js
, I had to set build.assetsPublicPath
to '/vue/'.
Another one is /vue/frontend/src/router/index.js
, the Vue Router mode can only be hash
, or I would see nothing changed when I entered the url such like /vue/home
. In other words, if Vue Router mode is history
, I can only see the interface rendered by /vue/frontend/src/App.vue
instead of the index route defined in router.