在刷新页面时,我遇到了404页在生产构建中找不到的问题。使用#路由RouterModule.forRoot(routes, { useHash: true })构建良好的工作状态。但我想要一条没有#的漂亮路线
我的模块看起来就像
  @NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    CoreModule,
    AppRoutingModule,
    AuthModule
  ],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: HttpInterceptorService,
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})发布于 2018-08-06 12:09:46
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>有关将生产生成部署到Apache的更多详细信息,请参见下面的链接:
https://github.com/mgechev/angular-seed/wiki/Deploying-prod-build-to-Apache-2
发布于 2018-11-03 09:30:56
在您的.htaccess位置创建index.html 文件
<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>注意:RewriteBase/示例/示例是您的index.html基url
<base href="/example/example/">
发布于 2019-09-02 09:46:41
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.htmlNginx
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>用于GitHub pages
you can't directly configure the GitHub Pages server, but you can add a 404 page. Copy index.html into 404.html. It will still be served as the 404 response, but the browser will process that page and load the app properly. It's also a good idea to serve from docs/ on master and to create a .nojekyll file用于Firebase托管
"rewrites": [ {
  "source": "**",
  "destination": "/index.html"
} ]https://stackoverflow.com/questions/51707010
复制相似问题