Hello,
I think I read this topic from a to z. when I click on the button I always have an error msg. if someone has a solution… thx
app-routing.module.ts
import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{ path: '', loadChildren: './login/login.module#LoginPageModule' },
{ path: 'app', loadChildren: './tabs/tabs.module#TabsPageModule' },
{ path: 'profile', loadChildren: './profile/profile.module#ProfilePageModule' },
{ path: 'profile-edit', loadChildren: './profile-edit/profile-edit.module#ProfileEditPageModule' },
{ path: 'sign-up1', loadChildren: './sign-up1/sign-up1.module#SignUp1PageModule' },
{ path: 'sign-up2', loadChildren: './sign-up2/sign-up2.module#SignUp2PageModule' },
{ path: 'tab1-result', loadChildren: './tab1-result/tab1-result.module#Tab1ResultPageModule' },
{ path: 'disconnect', loadChildren: './disconnect/disconnect.module#DisconnectPageModule' },
{ path: 'delete-account', loadChildren: './delete-account/delete-account.module#DeleteAccountPageModule' },
{ path: 'faq', loadChildren: './faq/faq.module#FaqPageModule' }
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule {}
login.page.html
<ion-header>
<ion-toolbar>
<ion-title>login</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-button (click)="navTabs()" expand="block">Navigate to tabs</ion-button>
</ion-content>
login.page.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
constructor() { }
ngOnInit() {
}
async navTabs() {
//you can use either of below
this.route.navigateByUrl('/app/tabs/(home:home)');
//this.navCtrl.navigateRoot('/app/tabs/(home:home)');
}
}
when I click on the button I always have an error msg.
RROR Error: Uncaught (in promise): TypeError: Cannot read property 'navigateByUrl' of undefined
TypeError: Cannot read property 'navigateByUrl' of undefined
at LoginPage.<anonymous> (login.page.ts:17)
at step (tslib.es6.js:97)
at Object.next (tslib.es6.js:78)
at tslib.es6.js:71
at new ZoneAwarePromise (zone.js:910)
at Module.__awaiter (tslib.es6.js:67)
at LoginPage.push../src/app/login/login.page.ts.LoginPage.navTabs (login.page.ts:15)
at Object.eval [as handleEvent] (LoginPage.html:8)
at handleEvent (core.js:23097)
at callWithDebugContext (core.js:24167)
at resolvePromise (zone.js:831)
at new ZoneAwarePromise (zone.js:913)
at Module.__awaiter (tslib.es6.js:67)
at LoginPage.push../src/app/login/login.page.ts.LoginPage.navTabs (login.page.ts:15)
at Object.eval [as handleEvent] (LoginPage.html:8)
at handleEvent (core.js:23097)
at callWithDebugContext (core.js:24167)
at Object.debugHandleEvent [as handleEvent] (core.js:23894)
at dispatchEvent (core.js:20546)
at core.js:20993