我的Angular ver-10电子商务项目-它的工作很好本地使用“ng serve”,但我发布使用“ng-build”和托管使用“http-server”页面它去主屏幕(例如: Jmeter 板http://192.168.1.20:8080)。但如果我点击任何链接(按钮-例如:购物车页面,订单页面,注册页面等)从 Jmeter 板页面,它不去,它得到错误,例如:“找不到此192.168.1.20页面找不到该网址的网页:HTTP错误404返回首页
这是我的路由代码“app.module.ts”
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { PathLocationStrategy, LocationStrategy,HashLocationStrategy } from '@angular/common';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ItemListComponent } from './item-list/item-list.component';
import { CartComponent } from './cart/cart.component';
import { ItemDetailsComponent } from './item-details/item-details.component';
import { HeaderaComponent } from './headera/headera.component';
import { HeaderbComponent } from './headerb/headerb.component';
import { HeadercComponent } from './headerc/headerc.component';
import { HeaderdComponent } from './headerd/headerd.component';
import { CheckoutComponent } from './checkout/checkout.component';
import { MyaccountComponent } from './myaccount/myaccount.component';
import { FooteraComponent } from './footera/footera.component';
import { FooterbComponent } from './footerb/footerb.component';
import { FootercComponent } from './footerc/footerc.component';
import { FooterdComponent } from './footerd/footerd.component';
import { PolicyComponent } from './policy/policy.component';
@NgModule({
declarations: [
AppComponent,
ItemListComponent,
CartComponent,
ItemDetailsComponent,
HeaderaComponent,
HeaderbComponent,
HeadercComponent,
HeaderdComponent,
CheckoutComponent,
MyaccountComponent,
FooteraComponent,
FooterbComponent,
FootercComponent,
FooterdComponent,
PolicyComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
],
providers: [ { provide: LocationStrategy,
useClass: PathLocationStrategy } ],
bootstrap: [AppComponent],
})
export class AppModule { }
“应用程序路由.模块.ts
import { Routes, RouterModule } from '@angular/router';
import { ItemListComponent } from './item-list/item-list.component';
import { CartComponent } from './cart/cart.component';
import { ItemDetailsComponent } from './item-details/item-details.component';
import { CheckoutComponent } from './checkout/checkout.component';
import { MyaccountComponent } from './myaccount/myaccount.component';
import {PolicyComponent} from './policy/policy.component';
const routes: Routes = [
{ path: "", component: ItemListComponent },
{ path: "cart", component: CartComponent },
{ path: "itemdetails", component: ItemDetailsComponent },
{ path: "checkout", component: CheckoutComponent },
{ path: "myaccount", component: MyaccountComponent },
{ path: "mypolicy", component: PolicyComponent },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
谢谢你。
3条答案
按热度按时间46qrfjad1#
将其保存为web.configxml文件并将其添加到服务器文件夹
am46iovg2#
"应用程序模块ts"
请添加以下输入:
只需删除旧的提供程序并添加上述值。问题是托管服务器始终查看"/#/home "或"/#/carts"
这是一个临时的解决方案,你可以从Angular 来理解路由的概念,比如基于路径和基于散列。
2hh7jdfx3#
只需将index.html复制并粘贴到它所在的目录中,然后将新文件重命名为404.html,如http-server文档中所述:* 如果找不到文件,将提供404.html。这可用于单页应用程序(SPA)托管以提供入口页面。*