angularangular-cliapp-shell

Angular-CLI App-Shell: Getting caught by "catch-all" route


I'm attempting to add App-Shell to my app. I've got a route guard that gets fired during the server build process due to a wildcard-redirect.

RouterModule

const routes: Routes = [
  {
    path: '',
    component: RouteOneComponent,
    canActivate: [AuthGuard]
  },
  {
    path: '**',
    redirectTo: ''
  }];

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

app.server.module

const routes: Routes = [ { path: 'app-shell', component: AppShellComponent }];

@NgModule({
  imports: [
    AppModule,
    ServerModule,
    RouterModule.forRoot(routes)
  ],
  bootstrap: [AppComponent],
  declarations: [AppShellComponent]
})
export class AppServerModule { }

Is there a way to have the server-build ignore the wildcard-redirect from the client AppRouterModule?


Solution

  • My issue ended up being less about the HttpClient call and more about the routes being called. I'll update the question to reflect. If you're using app-shell right now and your routes have a path: '**' in it, you'll need to do what's suggested in this issues's comment:

    https://github.com/angular/angular-cli/issues/8929#issuecomment-361884581