Fix SPA routing — page refresh returns 404 #33
Notifications
Total Time Spent: 10 minutes
connor
10 minutes
No due date set.
Dependencies
No dependencies set.
Reference: Shanty/Main#33
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The Yew frontend uses client-side routing via
yew-routerwithBrowserRouter. This uses the History API to manage URLs like/search,/library,/artists/5, etc. The problem: when the user navigates to a page (e.g.,/search) and then refreshes the browser, the Actix backend receives a request for/searchand tries to serve it as a static file — which doesn't exist. The result is a 404 or a blank page.This is a standard SPA routing issue. The fix is a server-side fallback: any request that doesn't match an
/api/*route and doesn't match a static file should returnindex.html, letting the Yew router handle the path client-side.Implementation
In
shanty-web/src/main.rs, the static file serving needs to be configured with a fallback. Actix-files doesn't have a built-in SPA fallback, so the approach is:index.htmlfor any non-API, non-file requeststatic/index.htmland returns it withtext/htmlcontent typeAlternatively, use
actix_files::NamedFileas a default handler:Acceptance Criteria
/searchand refreshing the page loads the search page correctly/library,/artists/5,/downloads,/settings)/api/*) still work normally and don't get caught by the fallback.js,.wasm,.css) are still served correctlyDependencies