Artanis Zeratul
Artanis Zeratul

Reputation: 1003

Angular 7 Routes not working when deployed to Apache 2 HTTPD Server


I have been trying to deploy my Angular 7 application to HTTPD Apache 2 Server. These are the steps I have taken:

  1. Setup a Virtual Host for my project
  2. Build --> ng build --prod
  3. Created and configured .htaccess as instructed here:

     <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
    

  4. Configured my app-routing.module.ts like this:

imports: [RouterModule.forRoot(routes ,{onSameUrlNavigation: 'reload'})]

My main page works but when I try to navigate through other routes e.g. http://myhostname/users/crud, it won't work anymore. Is there something I have missed here?

Thanks.

Upvotes: 0

Views: 1227

Answers (1)

user2455218
user2455218

Reputation: 11

Build --> ng build --prod --baseHref=/users/crud/

instead of

Build --> ng build --prod

Try the above code. That code work for me.

Upvotes: 1

Related Questions