Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

angular - 在角度服务器中使用延迟加载时,在此服务器上找不到请求的URL(The requested URL was not found on this server while using lazy loading in angular)

after i use lazy loading in my angular projects, it works well in local host but the problem is : when i upload project on server if users write URL just like www.oceanweb.ir and then click on contact us button they will direct to contact us page "www.oceanweb.ir/contact-us" correctly but if they enter same URL (www.oceanweb.ir/contact-us) by them self and write it in address bar an error will occur

(在我的有角项目中使用延迟加载后,它在本地主机上运行良好,但是问题是:当我在服务器上上传项目时,如果用户像www.oceanweb.ir一样写URL,然后单击“与我们联系”按钮,他们将直接联系我们页面“ www.oceanweb.ir/contact-us”正确,但是如果他们自己输入相同的URL(www.oceanweb.ir/contact-us)并将其写入地址栏中,则会发生错误)

Not Found The requested URL was not found on this server.

(找不到在此服务器上找不到请求的URL。)

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

(此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。)

here is part of my routing file

(这是我的路由文件的一部分)

const routes: Routes = [
  {
    path: "",
    component: LandingPageComponent
  },
  {
    path: "template",
    component: TemplateLayoutComponent,loadChildren: "./dashboard/template/template.module#TemplateModule"
  },
  {
    path: "contact-us",
    component: ContactUsLayoutComponent,loadChildren: "./dashboard/contact-us/contact-us.module#ContactUsModule"
  },
  {
    path: "education",
    component: EduLayoutComponent,loadChildren: "./dashboard/education/education.module#EducationModule"
  },
  {
    path: "recruitment",
    component: ReqLayoutComponent,loadChildren: "./dashboard/recruitment/recruitment.module#RecruitmentModule"
  }
];

  ask by amir marjani translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your app.module.ts file add this line to provide array

(在您的app.module.ts文件中,添加以下行以提供数组)

providers: [{ provide: LocationStrategy, useClass: HashLocationStrategy}]

It's will solve your problem

(这将解决您的问题)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...