0

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>
4
  • which command are u using for prod Commented Jun 12, 2020 at 10:41
  • i am using this for build ng build --prod Commented Jun 12, 2020 at 10:42
  • can you try with ng build --prod --base-href="http://dev.fobo.live" Commented Jun 12, 2020 at 10:44
  • still same error I get. No difference Commented Jun 12, 2020 at 10:49

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

6 Comments

The files are hosted in AWS server.
If it is in S3 and you are using S3 bucket as a hosting directory you can add a .htaccess file there. I am adding code to my answer
its not s3. I think its normal ec2 . I just connect with my command and take pull and run build
you need to check how it is hosted with Aws. There are options to re-rout to index.html. Try to implement and it should get resolved
So the issues is not with my code right ? The issue is from server ?
|
0

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

proxy and location configuration

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.