【问题标题】:Angular PathLocationStrategy refresh url on localhost:4200本地主机上的 Angular PathLocationStrategy 刷新 url:4200
【发布时间】:2020-12-18 19:13:26
【问题描述】:

我有 Angular 7.2 并使用 "useHash": false 并添加到 src .htaccess 文件中。在本地“npm start”上启动我的应用程序并在 localhost:4200 工作中运行。如果我导航到 localhost:4200/my-view 我会看到我的视图,但 如果重新加载页面(F5 浏览器重新加载)我会看到 404。 有什么想法吗?

【问题讨论】:

    标签: angular webpack


    【解决方案1】:

    问题是 proxy.conf.json

    {
       "/": {
          "target": "http://localhost:8080/api",
          "source": false
       }
    }
    

    我更改代码并工作

    {
       "/api": {
          "target": "http://localhost:8080/",
          "source": false
       }
    }
    
    

    【讨论】:

      【解决方案2】:

      .htaccess 文件

      <IfModule mod_rewrite.c>
          RewriteEngine On
      
          # -- REDIRECTION to https (optional):
          # If you need this, uncomment the next two commands
          # RewriteCond %{HTTPS} !on
          # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
          # --
      
          RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
          RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
      
          RewriteRule ^.*$ - [NC,L]
          RewriteRule ^(.*) index.html [NC,L]
      </IfModule>
      

      关于构建/服务

       ng serve/build --base-href 
      

      【讨论】:

        猜你喜欢
        • 2019-03-15
        • 2020-08-26
        • 1970-01-01
        • 2019-10-10
        • 2020-04-23
        • 2017-05-13
        • 2017-11-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多