0

I am working with micro frontend application I have two application one is shell and other is lead I am using secondary routing in lead application as following { path: '', children: [ { path: '', component: LeadShellComponent, children: [ { path: 'list', component: LeadListComponent, }, { path: 'board', component: LeadBoardComponent, }, { path: 'create', component: LeadCreateComponent, outlet: 'create', }, { path: ':Id', component: LeadDetailComponent, outlet: 'detail', }, ], }, ],

But my secondary router outlet is giving error in shell

core.js:6479 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: '2' Error: Cannot match any routes. URL Segment: '2'

I am trying to access this from shell as routerLink="lead"

Can any one help me with this?

2
  • Did you find any solution? I am also getting same error. Commented Apr 4, 2022 at 10:14
  • No I didn't find any Pls let me know if you if it out Commented Apr 6, 2022 at 3:23

1 Answer 1

0

Expose all your componets from remote as

// For remotes (please adjust)
        name: "remoteapp",
        filename: "remoteEntry.js",
        exposes: {
            './remoteAppModule': './/src/app/remote/remoteapp.module.ts',
            comp1Component: './/src/app/remote/comp1.component.ts',
            comp2Component: './/src/app/remote/comp2.component.ts',
            comp3Component: './/src/app/remote/comp3.component.ts',
        }

And in your shell app create a placeholder component and lazy load your remote app's comp1/comp2/comp3 as

In Shell Route :

{
    path: 'comp1',
    component : PlaceholderComponent
  },
  {
    path: 'comp2',
    component : PlaceholderComponent
  },
  {
    path: 'comp3',
    component : PlaceholderComponent
  },

PlaceHolderComponets looks like as :

@Component({
  selector: 'my-placeholder',
  template: `<div>
  <header #header></header>
  </div>`,
})
export class PlaceholderComponent {
    @ViewChild('header', { read: ViewContainerRef, static: true })
  headerContainer!: ViewContainerRef;

  constructor(private injector: Injector,
    private resolver: ComponentFactoryResolver,
    private router: Router) {}
  
  ngAfterViewInit(): void {
      let compIndex = "";
      if(this.router.url === "/comp1") {
        compIndex = "comp1Componet";
      } else if(this.router.url === "/comp2") {
        compIndex = "comp2Component";
      }else if(this.router.url === "/comp3") {
        compIndex = "comp3Component";
      }
    loadRemoteModule(
        {
            type:'module',
            remoteEntry : 'http://localhost:1003/remoteEntry.js',
            exposedModule : compIndex
        }
    )
        .then(module => {
          const factory = this.resolver.resolveComponentFactory(module[compIndex]);
          this.headerContainer?.createComponent(factory, undefined, this.injector);
        });
  }

}

Hope it will Works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.