mercedes-benz / mo360-ftk

MO360 Frontend Toolkit: A toolkit for single page applications (SPA) based on React and Typescript that allows to extract single features into microfrontends.
https://mercedes-benz.github.io/mo360-ftk/
MIT License
70 stars 20 forks source link

Error when router object should be used via injection #57

Open gruenich opened 11 months ago

gruenich commented 11 months ago

We are in the process of updating FTK in our application from version 0.3.2 to version 0.4.3. We followed the migration guidelines at https://github.com/mercedes-benz/mo360-ftk/blob/master/docs/guides/migration.md. Therefore, we schematically adapted our original init() function as follows:

function init(container: IDiContainer): void {
     container.bind<RouteConfigType>(serviceIds.routes).toConstantValue([
         {
             action: () => {
                 return () => <View1/>
             },
             name: "View1",
             path: '/view1',
         },
         {
             action: () => {
                 return () => <View2/>
             },
             name: "View2",
             path: '/view2',
         },
           ...

     ]);
}

export default() => {
     return (
         <>
             <App name="ApplicationName" init={init} config={config}>
                 <MuiThemeProvider theme={DUITheme}>
                     <CssBaseline>
                         <TranslationProvider translations={TranslationsI18n}>
                             <RouterProvider />
                         </TranslationProvider>
                     </CssBaseline>
                 </MuiThemeProvider>
             </app>
         </>
     );
};

Unfortunately, at runtime when we want to use the router object via injection

class View1 extends React.Component<IViewProps, IViewState> {

     @inject()
     public router!: RouterService;

      ...
      this.router.getRoute().name;
      ...

}

we get following error message:

Error: Can't inject router as no binding for type function Object() { [native code] } was found. Did you register it in the DiContainer? get inject.js:34

@prode81 Can you tell us what we are doing wrong here or how we can avoid this mistake?

DerLeviathan commented 9 months ago

Hi, we updated FTK from @daimler/ftk-core v0.4.3 to @mercedes-benz/ftk-core v0.4.5 but we are experiencing the exact same issue (same error message when using the injected router). @prode81 Can you please check why this is still the case and what we are doing wrong? Thank you & best regards

prode81 commented 9 months ago

Hey @DerLeviathan, we will investigate further. Sorry, this did not the trick for you.

DerLeviathan commented 9 months ago

Hi @prode81, do you already have some update on this issue. Thank you & best regards.