Deploying Angular CLI app

I'm having trouble with some odd routing behavior when I build my angular app in preparation for deployment. When I run the app locally using 'ng serve', navigation works just fine and everything seems to be ready for deployment. However after I run 'ng build --prod' and the dist folder is generated, if I launch the index.html navigation is broken in the following ways:

If I refresh the page, it fails to load (resulting in 404)

If I attempt to navigate to a page that uses a different component than the landing page it fails to load (404)


I have tried these suggested solutions:
Change the base href in index.html to <base href = "./">
Change AppModule providers to include {provide: LocationStrategy, useClass: HashLocationStrategy}
Change App.Routing to include RouterModule.forRoot(routes, {useHash: true})
LVL 9
the_b1ackfoxCIOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Have you checked your console for errors?
If you build as dev does it work?
Have you tried changing your <base href="path/to/index.html"> - assuming you are not running out of the webroot.
What version of Angular CLI are you using.

When you browse to the dist version of the site - where is it hosted - locally or remotely - what is the url to the index.html that you are using?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
@the_b1ackfox,

Do you still require assistance with this question? If so post back here, otherwise please can you close the question.
0
the_b1ackfoxCIOAuthor Commented:
If was the first time we had tried to do this.  Checking into the console we found a bunch or errors which led us to realize that we weren't deploying correctly.  Ended up changing the base href and deploying via AWS S3
0
the_b1ackfoxCIOAuthor Commented:
Thank you for the assist Julian!!
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Node.js

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.