William H.
William H.

Reputation: 93

How to host an Angular-CLI project on GoDaddy?

I rebuilt a small business website for my family using the angular-cli, it's all frontend code with no server. I am running into an issue hosting the site on GoDaddy. I was able to get the initial landing page in the index.html to display on the main url, but none of the routing is working correctly. Every page displays a 404. It was working fine locally.

I'm assuming this is a build issue, but I guess it could be an entirely different problem and I need a new approach.

My build steps:

Any help with this would be much appreciated. I can provide any necessary files, I just wasn't even sure where to start.

SOLUTION

I had not implemented the HashLocationStrategy in my router. After doing so everything worked as expected.

Upvotes: 2

Views: 2304

Answers (2)

Muhammad asif
Muhammad asif

Reputation: 41

I am using #Angular9. I successfully uploaded the zipped dist folder to a subdomain on the Godaddy shared hosting. Without implementing the HashLocationStrategy, I just set the base tag in index.html as followed and it worked as expected.

 <!doctype HTML>
 <html lang="en">
<head>
<meta charset="utf-8">
<title>MyApp</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>

This means #Angular9 app work for both PathLocationStrategy and HashLocationStrateg but for Single page application HashLocationStrategy is better. For Angular Universal PathLocationStrategy should be used.

Upvotes: 0

William H.
William H.

Reputation: 93

Solution

I had not implemented the HashLocationStrategy in my router. After doing so everything worked as expected.

Upvotes: 2

Related Questions