single-spa-angular icon indicating copy to clipboard operation
single-spa-angular copied to clipboard

Lazy-loaded routes not working in single-spa setup with Angular 19

Open karanmobilesentrix opened this issue 8 months ago • 5 comments

I’ve configured a single-spa root application along with two Angular 19 applications. The basic route configuration works fine when directly assigning components:

export const routes: Routes = [
  {
    path: "users",
    component: UsersComponent
  }
]

However, when I try to use lazy-loaded routes, the routing does not work as expected:

export const routes: Routes = [
  {
    path: "users",
    loadChildren: () =>
      import("./users/users.routes").then((m) => m.users)
  }
]

In main.single-spa.ts added as below

const lifecycles = singleSpaAngular({
    bootstrapFunction: (singleSpaProps) => {
        return bootstrapApplication(AppComponent, {
            providers: [
                ...getSingleSpaExtraProviders(),
                ...appConfig.providers,
                { provide: APP_BASE_HREF, useValue: '/user' },
            ],
        });
    },
    template: '<app-user />',
    Router,
    NgZone,
});

karanmobilesentrix avatar Apr 30 '25 10:04 karanmobilesentrix

Which version of single-spa-angular are you using? As far as I know, single-spa-angular@9 does not function with Angular 19. Single-spa-angular@10 is in beta and does work with Angular 19, but is a full rewrite that is not yet complete.

internettrans avatar Apr 30 '25 17:04 internettrans

We are close to release Angualr v20, any news on possible support for it ? I seen that single-spa-angular@10 is still in beta.

mklemarczyk avatar May 21 '25 15:05 mklemarczyk

See #545 to track Angular 20 support

internettrans avatar May 28 '25 04:05 internettrans

We have lazy-loading working with ng19. @karanmobilesentrix I think you are missing this at the top of main.ts:

import { setPublicPath } from 'systemjs-webpack-interop';

setPublicPath('foo'); // location of js assets

jamie-perkins-sp avatar Jun 12 '25 21:06 jamie-perkins-sp

For what it's worth, we are using single-spa-angular@9 with Angular 19 without issue. We are using esm bundles instead of systemjs or umd, but I really don't think that matters. It does mean you don't need to use systemjs-webpack-interop though.

manbearwiz avatar Sep 04 '25 19:09 manbearwiz