最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Angular application not handling routes correctly when served via Nginx - Stack Overflow

programmeradmin9浏览0评论

I have an Angular app deployed on Nginx, but I’m unable to navigate directly to different routes. The homepage loads fine, but accessing routes directly or refreshing the page results in a 404 Not Found error from Nginx.

I’ve used the following configuration in nginx.conf, but it’s not working:

    location / {
        try_files $uri $uri/ /index.html;
    }
   error_page 404 /index.html

How can I fix this and ensure Angular routing works properly?

Locally, I can access all routes without issues. For example, navigating to localhost:4200/troubleshoot correctly loads the component.

However, after deploying my Angular app on Nginx (domain: abc), I encounter the following issues:

Visiting abc/troubleshoot directly results in a 404 error.

When accessing abc, it correctly routes to abc/home, but refreshing the page also leads to a 404 error.

发布评论

评论列表(0)

  1. 暂无评论