0

I have a angular 2 cli app which I I have deployed using web hosting. I ran ng build --prod and copied contents of /dist to web-root folder, structure looks like following:

enter image description here

My index.html

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Invison</title>
    <base href="/">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">

    <!-- Material css -->
    <link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css" />
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">


</head>
<body>
    <app-root>Loading...</app-root>
</body>
</html>

The app is deployed correctly but when I click on a route it gives me 404 not found error. What am I doing wrong? Do I need to change base href in index file and how?

UPDATE:

my app.module:

const appRoutes: Routes = [
{ 
  path: '', 
  component: HomeComponent, 
},
{
   path: 'agreement', 
  component: AgreementComponent,
}
];


@NgModule({
  declarations: [
  AppComponent,
  HomeComponent,
  ContactComponent,
  HeaderComponent,
  ServicesComponent,
  AboutUsComponent,
  FooterComponent,
  AgreementComponent
  ],
  imports: [
  RouterModule.forRoot(appRoutes),
  BrowserModule,
  FormsModule,
  HttpModule,
  MdlModule,
  ScrollToModule.forRoot(),
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
Thinker
  • 5,326
  • 13
  • 61
  • 137

0 Answers0