Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to route in angular 4

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' }
  ])]
like image 727
Wafula Samuel Avatar asked Jun 29 '17 07:06

Wafula Samuel


1 Answers

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

like image 81
Sameera roshan Avatar answered Sep 22 '22 06:09

Sameera roshan