Hard reload or direct navigation to any page redirects to home page
Whenever I refresh the page, my site redirects to the home page. This happens on every single page. Trying to go directly to any page also redirects to the home page. This only happens when the site is deployed or built and ran using nuxt preview, this error does not happen in development.
3 Replies
Hi @Redeemr. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
This issue—where refreshing or directly navigating to any page redirects to the home page—typically points to a problem with your deployment configuration, especially when using static hosting or client-side rendering.
Based on the knowledge sources, here are the most likely causes and solutions:
1. Static Hosting Fallback Configuration
If you are deploying a statically generated or client-rendered Nuxt app, you need to ensure your static host is configured to serve the correct fallback file (usually
See more details in the Nuxt docs on static client-rendered app deployment. 2. Custom Redirect Middleware
If you have custom server middleware (such as a redirect that always sends users to
See example of redirect middleware. 3. Base URL or Router Configuration
If your app uses a custom base URL or hash mode, ensure your production server is configured to respect it. Misconfiguration can cause routing issues, especially if the base path is missing or incorrect in production.
See related issues with base URLs and routing. What to check: - If using static hosting, ensure your host is configured to serve
If you are deploying a statically generated or client-rendered Nuxt app, you need to ensure your static host is configured to serve the correct fallback file (usually
200.html
or index.html
) for all routes. If not, direct navigation to a non-root route may result in a 404 or an unexpected redirect to the home page. Nuxt generates index.html
, 200.html
, and 404.html
by default for static hosting. You must configure your host to serve 200.html
(or index.html
) for all unknown routes so that Nuxt can handle routing on the client side. If this is not set up, the server may always serve the home page or a 404, causing the behavior you describe.See more details in the Nuxt docs on static client-rendered app deployment. 2. Custom Redirect Middleware
If you have custom server middleware (such as a redirect that always sends users to
/
), this could cause all routes to redirect to the home page. For example, a middleware that redirects any non-root path to /
would result in this behavior.See example of redirect middleware. 3. Base URL or Router Configuration
If your app uses a custom base URL or hash mode, ensure your production server is configured to respect it. Misconfiguration can cause routing issues, especially if the base path is missing or incorrect in production.
See related issues with base URLs and routing. What to check: - If using static hosting, ensure your host is configured to serve
200.html
or index.html
for all routes.
- Review any custom server middleware for redirects that might be too broad.
- Double-check your router base and mode settings in your Nuxt config, and ensure your production environment matches your development setup.
If you provide more details about your deployment target (e.g., Netlify, Vercel, custom server), I can help with more specific configuration advice.
If these suggestions do not resolve your issue, the knowledge sources do not contain enough information to provide a more specific answer.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@148338264934318081> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
- I don't think it could be a hosting issue since I experience the same issue when running the build locally
- I do not have any custom middleware. The only middleware active might be from modules I have installed
- I don't have any special router configuration
Not sure how much this helps but when I clear all data on the site, the issue is resolved for the first refresh before immediately returning