#500 Slug issue
3 messages · Page 1 of 1 (latest)
The error message Couldn't resolve component "default" at "/product/:product()" when directly accessing a dynamic route (e.g., /product/555)—but not when navigating client-side—suggests an issue with how Nuxt resolves dynamic routes and components during server-side rendering or initial load.
Based on the knowledge sources, here are some possible causes and troubleshooting steps:
-
Dynamic Route Handling
Ensure your dynamic route is correctly set up in thepages/directory. For a route like/product/555, you should have a file named[product].vue(or[slug].vueif you use "slug" as the param) inside thepages/product/directory. The Nuxt file-based routing system relies on this naming convention to resolve dynamic routes properly. Double-check your directory and file names for typos or incorrect structure. See the Nuxt docs on dynamic routes. -
Component Export
The error message about not resolving the "default" component can occur if your page component does not have a default export. Make sure your dynamic page file (e.g.,[product].vue) exports a default component. -
Server vs. Client Navigation
The fact that navigation works client-side but fails on direct access or refresh suggests a possible mismatch between server and client builds, or a deployment/caching issue. This is a known problem in Nuxt, especially when using SSR and deploying behind a proxy or CDN. Clearing the browser cache or doing a hard refresh sometimes resolves it, but it's not a permanent fix. See similar issues discussed in this GitHub issue.
-
Nginx Proxy Configuration
If you're running Nuxt behind Nginx, ensure your Nginx config is correctly proxying all requests to the Nuxt server, especially for dynamic routes. A typical config looks like:server { listen 80; server_name your-domain.com; location / { proxy_pass <http://localhost:3000;> } }This ensures that all routes—including dynamic ones—are handled by Nuxt, not by Nginx's static file serving. See this example config.
-
Build/Deployment Issues
If you recently updated Nuxt, ensure you have rebuilt your project (npm run build) and restarted the server. Sometimes, old build artifacts can cause mismatches. -
Client Cache Issues
There are reports that client-side caching can cause this error after deployments. Forcing a hard refresh or clearing the cache can temporarily resolve it, but you may need to adjust your deployment or cache-busting strategy to prevent this in production see discussion.
Summary:
- Double-check your dynamic route file structure and naming.
- Ensure your dynamic page component has a default export.
- Verify your Nginx proxy passes all requests to Nuxt.
- Rebuild and restart your Nuxt server after updates.
- Consider cache-busting strategies if the issue persists after deployment.