Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!