How to set base url in angular 6 app (getting 404 page after refreshing)?

Issue

I have followed the below procedure.

  1. ng build –base-href=/myapp/
  2. Deployed into the tomcat server
  3. Accessing: http://localhost:8080/myapp/ (open home page)

After refreshing the home page, it is giving a 404 error page.

Solution

try using HashLocationStrategy. Put useHash: true while defining your routes:

@NgModule({
  imports: [
    ...
    RouterModule.forRoot(routes, { useHash: true })

https://angular.io/guide/router#hashlocationstrategy

Answered By – Abdul Rafay

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.