-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Closed
Labels
Description
Default Routes for SPA's -- what's the correct way to do them
Suppose you have an SPA where https://example.com/foo/bar/spam should be routed in JavaScript, not in Python.
As far as I can tell, the "correct" way to do that seems something like this:
async def default_route(scope, receive, send):
request = Request(scope, receive=receive, send=send)
response = templates.TemplateResponse("spa.html", {'request': request})
await response(scope, receive, send)
app.router.default = default_route
That seems a little dirty however, since it's jumping outside both FastAPI and Starlette's documentation and just setting default to a function that then recreates the request object. It isn't very FastAPI-y.
Is there perhaps another, alternative way to establish a default route?