bArraxas
bArraxas

Reputation: 664

How not remove "index.html"?

I have a problem with my Angular 6 app.

My app url : my-server/my-app/index.html.

When the app is loaded, the url is automaticaly rewrited without the "index.html". It's a big problem because deep links are unusable.

Exemple : my-server/my-app/deep-route-1/6

The app work well, but if an user want to copy/paste this deep link, the server http respond 404 (and it's normal i think).

How to solve this problem?

Here my routes declaration:

const routes: Routes = [
  //{ path: '', redirectTo: '', pathMatch: 'full' },
  { path: 'simulation/:id', component: SimulateurComponent, resolve: { vm: SimulationResolver } },
  { path: 'parametres/:nedt', component: ParamsComponent, resolve: { params: ParamsResolver } }
]

@NgModule({
  imports: [ RouterModule.forRoot(routes) ],
  exports: [ RouterModule ]
})

EDIT

After searchs, it seems it's a new particularity of Angluar.io. Angular 6 use "html 5 urls" that's why he automaticaly remove the "index.html" in the url.

To counter that, 2 solutions : - A complicated (rewrite url) - no time to test it - A simple : use the angular.js technique :

@NgModule({
  imports: [ RouterModule.forRoot(routes, { useHash: true }) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule {}

The "usehash" is magic ;)

Upvotes: 0

Views: 1237

Answers (1)

Francesco Manicardi
Francesco Manicardi

Reputation: 809

This is an old question but I just had the same exact problem.

I solved it by changing the build command that i use during deployment:

BEFORE (NOT working, removes index.html :( )

ng build --base-href /www/app/

After (WORKS, doesn't remove index.html :) )

ng build --base-href /www/app/index.html

Upvotes: 1

Related Questions