【发布时间】:2018-12-26 13:31:29
【问题描述】:
我制作了一个带有路由组件的 Angular 项目。我已经处理了一些 URL 处理,例如用户手动点击 URL:如果 URL 存在,它会转到 app-routing-module.ts 中定义的 URL 组件,如果 URL不存在,它显示代码 PagenotFoundComponent 中定义的错误页面。 例如
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {HomeComponent} from './component/home.component';
import {AboutusComponent} from './component/aboutus.component';
import {SupportComponent} from './component/support.component';
import {PurchaseComponent} from './component/purchase.component';
import {PagenotfoundComponent} from './component/pagenotfound.component';
import {HowitworksComponent} from './component/howitworks.component';
import {ProductComponent} from './component/product.component';
import { ProductVarientDetailsComponent } from './component/product-varient-details.component';
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full'},
{ path: 'home', component: HomeComponent},
{ path: 'about-us', component: AboutusComponent},
{ path: 'how-it-works', component: HowitworksComponent},
{ path: 'support', component: SupportComponent},
{ path: 'purchase', component: PurchaseComponent},
{ path: 'product/:name/details', component: ProductComponent},
{ path: 'product-variants', component: ProductVarientDetailsComponent},
{ path: '**', component: PagenotfoundComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
export const routingComponents = [HomeComponent, AboutusComponent, SupportComponent,
PurchaseComponent, PagenotfoundComponent, HowitworksComponent,
ProductComponent, ProductVarientDetailsComponent];
所以当我手动点击 localhost:4200/home 时,它会显示 HomeComponent Page,如果我这样做 localhost:4200/sdnbgbdfgbh,它会显示本地服务器上的 PagenotfoundComponent Page。
然后我转到此链接:https://angular.io/guide/deployment 来部署我的 Angular 应用程序。我按照文档中的步骤进行操作。说。
我的应用程序现在可以完全运行,但是当我手动输入一些 url 时,它会显示 Apache Server Page Not Found。只是这个东西在 Angular 应用程序中不起作用。
我已将我的应用程序部署在 Apache 服务器上的 AWS EC2 端口 80 上。
【问题讨论】:
-
你能用 .htaccess 内容更新你的问题吗?要清楚地了解需要查看 .htaccess 配置。
-
我的 .htaccess 文件是空的
-
我在 .htaccess 文件中添加了
RewriteEngine on RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^(.*) /index.html [NC,L],但它仍然无法正常工作。
标签: amazon-ec2 deployment angular6 angular-routing