Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
FastAPI app with Angular routing returning 404 and blank page on refresh

I am mounting an Angular app with routing with fastAPI, and everything loads correctly the first time, but when I refresh the page that includes my Angular routing, I get a 404 error on the route.

app.mount("/app", StaticFiles(directory=str("ui/"), html=True))

# this loads the app at /app/my-angular-route
@app.get("/")
def redirect_to_app() -> RedirectResponse:
    return RedirectResponse("/app/")

# this route never gets called even though I expect it to when refreshing /app/my-angular-route
@app.get("/app/{rest_of_path:path}")
def redirect_to_app(rest_of_path) -> RedirectResponse:
    return RedirectResponse("/app/")

I believe that when it sees the /app path, it automatically goes to the mounting files instead of looking at the routes I have defined.

Is there a way to first check the routes before redirecting to the mounted static files? Also is it possible to keep my Angular routing intact (ie remember what route I’m at) when I refresh the page so that it always loads the current page and does not load blank or redirect back to the home page?

I tried using the solution in this thread but am getting the error

TypeError: cannot unpack non-iterable coroutine object

EDIT: It seems I was able to get the routes to take precedent by just moving the mount after them, but as expected this is creating a circular call of the app routes calling the mount and then the mount calling the app routes. What is the best way to point to the app mount regardless of the route, but in such a way that it then switches over to my Angular routing instead of the fastAPI routing?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda