I have an angular 4 project and when I run it from localhost:4200/route-a
, it works fine and when I refresh the browser, all works well as expected. However, when I build it with ng build
and run it from apache, navigating to localhost/route-a
returns a 404
. Here is my code for routing:
imports: [BrowserModule, HttpModule, FormsModule, RouterModule.forRoot([
{ path: 'home', component: HomeComponent },
{ path: 'route-a', component: RouteAComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' }
])]
As of Apache version 2.2.16, you can use the FallbackResource directive for this:
<Directory "/var/www/my_blog">
FallbackResource index.php
</Directory>
Check https://httpd.apache.org/docs/trunk/rewrite/remapping.html#fallback-resource
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With