8

So to deploy angular2 app we simply upload all production files to a bucket just as described here. (deploy static website).

But how can we redirect all urls to index.html so that angular2 router can take care of them. We can set Main Page from website configuration of bucket. But we cannot specify that all urls should redirect to index.html.

Currently any url other than Main Page results in 404 page not found.

There is similar question on SO for amazon S3, but cannot find one for google cloud.

Community
  • 1
  • 1
hhsadiq
  • 2,871
  • 1
  • 25
  • 39

1 Answers1

8

I solved this issue by using a hack, not sure what the proper way to do this. But atleast this worked.

  1. Open storage in console.cloud.google.com. enter image description here

  2. Click edit website configuration in buckets listing. Click far right in row with three dots. And select edit configuratione enter image description here

  3. Enter your main page same as 404 page. The angular routing will work fine this way. enter image description here

hhsadiq
  • 2,871
  • 1
  • 25
  • 39
  • 2
    The issue with @hhsadiq is that the initial get request is going to return a 404 HTTP code, it is going to render the page, but with that error, that affects SEO a lot and if you set that application URL in a Google Ads campaign it is going to fail because of that. – Luis Suarez May 22 '19 at 22:14