Santosh
Santosh

Reputation: 3807

Angular file not found after deploy to server for route specific url

My angular app works perfectly on my localhost:4200. Now I have deploy it to the server. The homepage looks okay. It redirect to error page due to invalid URL. The valid url of the page is this.

I get valid page if the url has pass two route params in my local but for some reason it is not working on live server.

const routes: Routes = [
  {
    path:":restaurantId/:mobileNo",
    component: LandingComponent,
  },
  {
    path:"",
    component: LandingComponent,
    canActivate: [AuthGuard]

  },
  {
    path:"error",
    component: ErrorComponent,
  },
];

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Freshii</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root></app-root>
</body>
</html>

Upvotes: 0

Views: 828

Answers (2)

Santosh
Santosh

Reputation: 3807

After this configuration made to this server ngix it is fix now.

proxy and location configuration

Upvotes: 0

Dewanshu
Dewanshu

Reputation: 534

This is because you are trying to access the url directly and you server does not have any information about this rout. This rout is only recognised by your angular app. As i am not aware of your server configration now so i am not able to give you exact solution to fix it. But if its an apache you can create an htaccess file and add the onfigration to first come at index.html before throwing an error

Upvotes: 2

Related Questions