setRoot from LogIn-Page

In my app there’s a login-page with an startApp()-function like this:

startApp() {
  if (this.lastPage == undefined) {
    this.appCtrl.getRootNav().setRoot(Homepage);
  } else {
    this.appCtrl.getRootNav().setRoot(this.lastPage);
  }
}

Where this.appCtrl is from type App.

The first time it is working and after some time of idleness it is automatically logged off and the login-page is shown asking for the passkey again.

If the passkey is okay there are two different errors:

  1. If lastPage is HomePage

    ERROR Error: Uncaught (in promise): invalid link: HomePage
    at c (polyfills.js:3)
    at Object.reject (polyfills.js:3)
    at NavControllerBase._fireError (main.js:48111)
    at NavControllerBase._failed (main.js:48099)
    at main.js:48154
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (main.js:4501)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3

  2. If lastPage isn’t Homepage:

    Error: Type OtherPage is part of the declarations of 2 modules: AppModule and OtherPageModule! Please consider moving OtherPage to a higher module that imports AppModule and OtherPageModule. You can also create a new NgModule that exports and includes OtherPage then import that NgModule in AppModule and OtherPageModule.

    ERROR Error: Uncaught (in promise): Error: Type OtherPage is part of the declarations of 2 modules: AppModule and OtherPageModule! Please consider moving OtherPage to a higher module that imports AppModule and OtherPageModule. You can also create a new NgModule that exports and includes OtherPage then import that NgModule in AppModule and OtherPageModule.

    at syntaxError (file:///android_asset/www/build/main.js:90373:34)
    

    at CompileMetadataResolver._addTypeToModule (file:///android_asset/www/build/main.js:103478:31)
    at file:///android_asset/www/build/main.js:103366:27
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (file:///android_asset/www/build/main.js:103357:54)
    at JitCompiler._loadModules (file:///android_asset/www/build/main.js:114463:66)
    at JitCompiler._compileModuleAndComponents (file:///android_asset/www/build/main.js:114422:52)
    at JitCompiler.compileModuleAsync (file:///android_asset/www/build/main.js:114384:23)
    at ModuleBoundCompiler.compileModuleAsync (file:///android_asset/www/build/main.js:114752:31)
    at file:///android_asset/www/build/main.js:83269:25
    at syntaxError (file:///android_asset/www/build/main.js:90373:34)
    at CompileMetadataResolver._addTypeToModule (file:///android_asset/www/build/main.js:103478:31)
    at file:///android_asset/www/build/main.js:103366:27
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (file:///android_asset/www/build/main.js:103357:54)
    at JitCompiler._loadModules (file:///android_asset/www/build/main.js:114463:66)
    at JitCompiler._compileModuleAndComponents (file:///android_asset/www/build/main.js:114422:52)
    at JitCompiler.compileModuleAsync (file:///android_asset/www/build/main.js:114384:23)
    at ModuleBoundCompiler.compileModuleAsync (file:///android_asset/www/build/main.js:114752:31)
    at file:///android_asset/www/build/main.js:83269:25
    at c (file:///android_asset/www/build/polyfills.js:3:13535)
    at Object.reject (file:///android_asset/www/build/polyfills.js:3:12891)
    at NavControllerBase._fireError (file:///android_asset/www/build/main.js:48111:16)
    at NavControllerBase._failed (file:///android_asset/www/build/main.js:48099:14)
    at file:///android_asset/www/build/main.js:48154:59
    at t.invoke (file:///android_asset/www/build/polyfills.js:3:9283)
    at Object.onInvoke (file:///android_asset/www/build/main.js:4501:37)
    at t.invoke (file:///android_asset/www/build/polyfills.js:3:9223)
    at r.run (file:///android_asset/www/build/polyfills.js:3:4452)
    at file:///android_asset/www/build/polyfills.js:3:14076

Can you help me? It seems to me, that it’s a problem of lazy loading, but I don’t know how to solve. Thank you in advance!

I would strongly suggest moving this logic into the app component and out of the login page. The app component is responsible for handling root navigation, so all logic involving root navigation should be confined to it.

Secondly, if you’re lazy loading a page, you must pass its name as a string to the navigation system, not the class. You also need to take OtherPage out of the app module if it has its own.