What Can I Do If a 404 Error Is Displayed When I Refresh a Page with Vue Router in History Mode?
Vue Router supports two routing modes: hash mode and history mode. The hash mode (URL example: example.com/#/user) does not require server configuration, whereas the history mode (URL example: example.com/user) produces cleaner URLs but requires server configuration.
Symptom: In history mode, when a user directly accesses a page other than the home page (for example, example.com/user), the server searches for the corresponding physical file (/user). If the file does not exist, the server returns a 404 error.
Solution: When configuring static website hosting, set the default 404 error page to index.html. This way, when a user accesses or refreshes a page other than the home page and the requested page does not exist, all paths are redirected to the home page of the application, allowing the frontend JavaScript to correctly handle the route.