'Angular RouterModule : how to ignore path in proxy.conf.json?

I'm looking to ignore a path (in this example /backexample) in my RouterModule which is present on my proxy.conf.json for calling my back api.

I'm using Angular 12.

This my app-routing.module.ts :

const routes: Routes = [
  {
    path: 'view',
    component: ViewComponent
  },
  {
    path: '',
    component: HomeComponent
  }
];

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

My proxy.conf.json :

"/backexample/public/api/v1/*" : {
    "target": "http://localhost:8080/",
    "pathRewrite": {"^/backexample": ""},
    "secure": false,
    "changeOrigin": false
}

On localhost building, I don't encounter any problem during the call of my API ; My localhost:4200/backexample/blabla browser call will succesfully pass the routing module without redirection.

However, after made a deployment with ng build --configuration production and when i'm trying the application on remote server : My 'https://myfakeserver.com/backexample/blabla` request will throw this error :

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'backexample/blabla'

My index.html base href is set to '/'

Do you have any idea how to fix this problem ? And ignore the path backexample from my RouterModule ?

Regards



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source