代码之家  ›  专栏  ›  技术社区  ›  Krishna Chaitanya

角度:在prod模式下点击refresh后url改变

  •  1
  • Krishna Chaitanya  · 技术社区  · 7 年前

    我已经在http服务器上构建并部署了一个角度应用程序。下面是我请求 index.html 第页。

    http://localhost:8080/contextRoot/index.html

    页面加载并将url更改为 http://localhost:8080/contextRoot/XYZ

    刷新此页时,显示错误404,未找到。

    如何请求angular不将url更改为 http://localhost:8080/contextroot/xyz 而是用一些像 http://localhost:8080/contextRoot/index.html#Login 就像Angularjs那样

    2 回复  |  直到 7 年前
        1
  •  1
  •   danday74    7 年前

    你没有。

    角度应用程序是单页应用程序(SPA)。

    单个页面称为index.html

    不管路由/url是什么,您总是提供index.html

    angular cli dev server aka webpack dev server可直接配置此功能。

    当您将Angular应用程序部署到其他Web服务器时,您需要自己配置它。

    只需谷歌“nginx角度单页应用配置”或 “单页应用程序的Apache配置”

    然后相应地配置您的web服务器。

    PS在刷新中得到404的原因是因为Web服务器的默认行为是查找/上下文上下文/ XYZ/NOTEX.HTML,这显然不存在。您需要覆盖上述默认行为。

        2
  •  0
  •   madrick    7 年前

    你在nginx上跑步吗?如果在nginx中运行生产构建,请确保将此代码放入配置文件中

    location / {
        try_files $uri $uri/ /index.html; # This will allow you to refresh page in your angular app. Which will not give error 404.
    }
    
    推荐文章