当Angular 7重写与Apache不正确工作时,可能有几个原因导致这个问题。下面是一些可能的解决方法和代码示例:
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
确保将/path/to/your/angular/app
替换为你的Angular应用程序的实际路径。
app-routing.module.ts
文件中,确保你已启用HTML5路由模式:import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AppComponent } from './app.component';
const routes: Routes = [
{ path: '', component: AppComponent },
// other routes...
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: false })],
exports: [RouterModule]
})
export class AppRoutingModule { }
确保将useHash
设置为false
。
确保你的Angular应用程序已正确配置以生成正确的基路径。在你的Angular应用程序的index.html
文件中,确保你的
元素中的href
属性正确设置为你的应用程序的基路径。
确保你的Apache服务器已启用了mod_rewrite
模块。在你的Apache配置文件中,确保以下行没有被注释掉:
LoadModule rewrite_module modules/mod_rewrite.so
.htaccess
文件,并添加以下重写规则:RewriteEngine On
RewriteBase /path/to/your/angular/app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [L]
确保将/path/to/your/angular/app/
替换为你的Angular应用程序的实际路径。
以上解决方法应该能够解决Angular 7重写与Apache不正确工作的问题。如果问题仍然存在,请检查你的Apache错误日志以获取更多的错误信息。