0

I have an angular project that is deployed aws s3

I built the project using ng build --prod

I copied the dist folder files in the s3 bucket..

The page loads smoothly for the first time but when i reload it .. it shows me this error

GET https://fellowgenius.com/facade 404

How do I solve this?

Here is my index html page:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>FellowGenius</title>
    <base href="./" />
    <script>
      var global = global || window;
      var Buffer = Buffer || [];
      var process = process || {
        env: { DEBUG: undefined },
        version: [],
      };
    </script>
    <link rel="icon" type="image/x-icon" href="favicon.ico" />
   <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>

  <body class="mat-typography">
    <app-root></app-root>
  </body>
</html>
3
  • Did you enable static website hosting on the bucket? Commented Jul 21, 2020 at 16:49
  • @jordanm yes i enabled it Commented Jul 21, 2020 at 17:16
  • Did you set the error document to index.html? Commented Jul 21, 2020 at 17:26

2 Answers 2

1

By default, HTML5 history is used for reusing in Angular2.

To fix the 404 error, you need to update your server to serve the index.html file for each route path you defined.

If you want to switch to the HashBang approach, you need to use this configuration:

import {bootstrap} from 'angular2/platform/browser';
import {provide} from 'angular2/core';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {LocationStrategy, HashLocationStrategy} from '@angular/common';

import {MyApp} from './myapp';

bootstrap(MyApp, [
  ROUTER_PROVIDERS,
  {provide: LocationStrategy, useClass: HashLocationStrategy}
]);

Reference: When I refresh my website I get a 404. This is with Angular2 and firebase

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

Comments

0

I fixed this problem using two simultaneous ways. One of the ways was used in the topic above and the other in the topic: When I refresh my website I get a 404. This is with Angular2 and firebase . I used both ways because my route files were separate from app.module.ts:

// APP.MODULE.TS:

...
    import { HashLocationStrategy, LocationStrategy } from '@angular/common'; // put this import
    
    @NgModule({
        declarations: [AppComponent, WelcomeComponent, ConfirmationDialogComponent,
              ],
        providers: [
        provideHttpClient(withInterceptors([jwtInterceptor, errorInterceptor, spinnerInterceptor])),
        { provide: LocationStrategy, useClass: HashLocationStrategy }, // put this code
        ],
        bootstrap: [AppComponent],
...

// APP.ROUTING.MODULE.TS:

...
@NgModule({
  // imports: [RouterModule.forRoot(routes, { bindToComponentInputs: true })],
  imports: [RouterModule.forRoot(routes, { useHash: true })], //put this code
  exports: [RouterModule],
})
export class AppRoutingModule {}

...

1 Comment

Hi, try to specify over each file example the according description to clarify why use one way or the other way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.