Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 6构建,刷新页面时未找到错误404_Angular_Angular Routing - Fatal编程技术网

Angular 6构建,刷新页面时未找到错误404

Angular 6构建,刷新页面时未找到错误404,angular,angular-routing,Angular,Angular Routing,刷新页面时,我在生产构建中遇到了一个问题404页面未找到。 使用#路由RouterModule.forRoot(路由,{useHash:true})构建工作正常。但是我想要一条没有# 我的模块看起来像 @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, HttpClientModule, CoreModule, AppR

刷新页面时,我在生产构建中遇到了一个问题404页面未找到。 使用
#
路由
RouterModule.forRoot(路由,{useHash:true})
构建工作正常。但是我想要一条没有
#

我的模块看起来像

  @NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    CoreModule,
    AppRoutingModule,
    AuthModule
  ],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: HttpInterceptorService,
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})

页面刷新时显示404未找到的原因是所有角度路由都应通过index.html文件提供服务

您可以通过添加包含以下内容的.htaccess文件(位于index.html所在的同一目录中)来解决此问题

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.html [L]
</IfModule>

重新启动发动机
重写基/
重写规则^index\.html$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。index.html[L]
有关将生产构建部署到Apache的更多详细信息,请参见下面的链接:


在index.html位置创建.htaccess文件

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /example/example/
   RewriteRule ^index\.html$ - [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . index.html [L]
 </IfModule>

重新启动发动机
重写基本/示例/示例/
重写规则^index\.html$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则。index.html[L]
注意:RewriteBase/example/example是您的index.html基本url


对于Apache

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
对于Nginx

try_files $uri $uri/ /index.html;
对于IIS

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/index.html" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
对于Firebase主机

"rewrites": [ {
  "source": "**",
  "destination": "/index.html"
} ]

深度URL称为SPA支持,默认情况下节点的http服务器不支持,但可以通过这种方式启用-

http-server --gzip --proxy http://localhost:8080?

您正在使用哪个web服务器进行生产构建部署?现在我正在Apachetry上测试这篇简单的文章来解决此问题我正在尝试将一个单页Angular 6应用程序部署到SharePoint。我的问题一直和原来的海报一样。我尝试了您的解决方案,但没有更改结果。此解决方案适用于apache web服务器,而不是SharePoint
http-server --gzip --proxy http://localhost:8080?