This project sample shows how to use SvelteKit frontend with Flask backend.
Flask does not automatically translate /a
into /a/index.html
even if an index.html
file exists. Due to this, it's necessary to build the sveltekit as a pure SPA:
Before following these steps, please note:
Add these to your src/routes/+layout.ts
or src/routes/+layout.js
file.
export const ssr = false;
export const prerender = false;
Set kit options as shown below (in svelte.config.js
):
{
kit: {
prerender: { entries: [] }, // disable prerender
adapter: adapter({
fallback: "index.html",
}),
},
}
In your flask file, add the following routes:
@app.route("/")
def index_route():
return send_from_directory('./build', 'index.html')
@app.route("/<path:path>")
def static_files(path):
return send_from_directory('./build', path)