Unable to route to Menu Page from login page in IonicAngular2 - Redirect to calling url after successful loginCapture redirect route with guard in Angular2Angular 2: TypeError: is not a functionAngular 2 Routing Does Not Work When Deployed to Http ServerLazy Load to route other than empty route in Angular 2Angular 4 ERROR Error: Uncaught (in promise): RangeError: Maximum call stack size exceededrouting navigate method not redirecting to targeted componentAfter Upgrade from Angular 5 to 6: Error: Uncaught (in promise): TypeError: undefined is not a functionNot getting the expected page after log out and login back.Ionic 4 Routing to a view with tabs triggers full page reload
Can a 40amp breaker be used safely and without issue with a 40amp device on 6AWG wire?
Interview was just a one hour panel. Got an offer the next day; do I accept or is this a red flag?
Can an open source licence be revoked if it violates employer's IP?
What things do I only get a limited opportunity to take photos of?
What is wind "CALM"?
Leveling up and Getting Items!
Can an escape pod land on Earth from orbit and not be immediately detected?
Relationship between a determinant and the roots of a cubic equation
Is it possible to have battery technology that can't be duplicated?
How can I detect if I'm in a subshell?
Print the phrase "And she said, 'But that's his.'" using only the alphabet
Do items with curse of vanishing disappear from shulker boxes?
Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?
Does WiFi affect the quality of images downloaded from the internet?
Difference between "drift" and "wander"
How to know whether to write accidentals as sharps or flats?
Is it a good security practice to force employees hide their employer to avoid being targeted?
What does the output current rating from an H-Bridge's datasheet really mean?
ISP is not hashing the password I log in with online. Should I take any action?
Why is Skinner so awkward in Hot Fuzz?
Support Structures for Green beans and peas
New Site Design!
What did the 8086 (and 8088) do upon encountering an illegal instruction?
Is it possible to install Firefox on Ubuntu with no desktop enviroment?
Unable to route to Menu Page from login page in Ionic
Angular2 - Redirect to calling url after successful loginCapture redirect route with guard in Angular2Angular 2: TypeError: is not a functionAngular 2 Routing Does Not Work When Deployed to Http ServerLazy Load to route other than empty route in Angular 2Angular 4 ERROR Error: Uncaught (in promise): RangeError: Maximum call stack size exceededrouting navigate method not redirecting to targeted componentAfter Upgrade from Angular 5 to 6: Error: Uncaught (in promise): TypeError: undefined is not a functionNot getting the expected page after log out and login back.Ionic 4 Routing to a view with tabs triggers full page reload
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have created login with menu pages in ionic. I am not able to go to menu page after authentication stage. It didn't show the error too.
Could you please help me?
Here is my code I have tried.
app.routing.module.ts
import NgModule from '@angular/core';
import PreloadAllModules, RouterModule, Routes from '@angular/router';
import AuthGuard from './guards/auth.guard';
const routes: Routes = [
path: '', redirectTo: 'login', pathMatch: 'full' ,
path: 'login', loadChildren: './public/login/login.module#LoginPageModule' ,
path: 'menu', canActivate: [AuthGuard],
loadChildren: './protected/menu/menu.module#MenuPageModule'
,
path: 'reportlist', canActivate: [AuthGuard],loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
];
@NgModule(
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
)
export class AppRoutingModule
app.component.ts
import Component from '@angular/core';
import Router from '@angular/router';
import Platform from '@ionic/angular';
import SplashScreen from '@ionic-native/splash-screen/ngx';
import StatusBar from '@ionic-native/status-bar/ngx';
import OraclemcsService from './services/oraclemcs.service';
@Component(
selector: 'app-root',
templateUrl: 'app.component.html'
)
export class AppComponent
public appPages = [
title: 'Login',
url: '/login',
icon: 'login',
render: true
,
/*
title: 'ReportList',
url: '/reportlist',
icon: 'list',
render: false
, */
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
public stateFlag = false;
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private authService: OraclemcsService,
private router: Router
)
this.initializeApp();
initializeApp()
this.platform.ready().then(() =>
this.statusBar.styleDefault();
this.splashScreen.hide();
this.authService.authenticationState.subscribe(state=>
if (state)
this.stateFlag = true;
this.router.navigate(['menu']);
// this.router.navigate(['menu']);
this.appPages = [
title: 'profile',
url: '/profile',
icon: 'person',
render: false
,
title: 'reportList',
url: '/reportlist',
icon: 'list',
render: false
,
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
else
this.router.navigate(['login']);
this.stateFlag = false;
this.appPages = [
title: 'Login',
url: '/login',
icon: 'log-in',
render: true
];
);
);
logout()
this.authService.logout();
login.page.html
<ion-header>
<ion-toolbar>
<ion-buttons slot="end">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title color="primary">Care Mobile</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-row justify-content-center>
<ion-col align-self-center size-md="6" size-lg="5" size-xs="12">
<div text-center>
<ion-text color="primary">
<h3>Login</h3>
</ion-text>
</div>
<div padding>
<ion-item>
<ion-input type="text" [(ngModel)]="username" placeholder="Username"></ion-input>
</ion-item>
<ion-item>
<ion-input type="password" [(ngModel)]="password" placeholder="Password"></ion-input>
</ion-item>
</div>
<div padding>
<ion-button color="primary" (click)="login()" expand="block">Login</ion-button>
<!--ion-button (click)="callweblogicservice()" expand="block">CallService</ion-button-->
<!--ion-button (click)="logoutweblogic()" expand="block">weblogic logout</ion-button-->
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
login.module.ts
import NgModule from '@angular/core';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import LoginPage from './login.page';
const routes: Routes = [
path: '',
component: LoginPage
];
@NgModule(
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [LoginPage]
)
export class LoginPageModule
login.page.ts
import Component, OnInit from '@angular/core';
import OraclemcsService from './../../services/oraclemcs.service';
import MenuController from '@ionic/angular';
@Component(
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
)
export class LoginPage implements OnInit
public username: string;
public password: string;
constructor(private authService: OraclemcsService, private NavCtrl: MenuController )
ngOnInit()
login()
console.log('User Name & Password' + this.username + this.password);
this.authService.login(this.username, this.password);
this.password = null;
//code to login to WEBLOGIC
//this.authService.loginWeblogic(this.username , this.password);
menu.page.html
<ion-split-pane>
<ion-menu contentId="content">
<ion-header>
<ion-toolbar>
<ion-title>CARE</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-menu-toggle auto-hide="false" *ngFor="let p of pages">
<ion-item [routerLink]="p.url" routerDirection="root" [class.active-item]="selectedPath === p.url">
<ion-label>
p.title
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet id="content" main></ion-router-outlet>
</ion-split-pane>
menu.module.ts
import NgModule from '@angular/core';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import MenuPage from './menu.page';
import AuthGuard from 'src/app/guards/auth.guard';
//import BrowserModule from '@angular/platform-browser';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import HttpClientModule from '@angular/common/http';
//import AppRoutingModule from 'src/app/app-routing.module';
const routes: Routes = [
path: 'menu',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
,
path: '',
redirectTo: './reportlist/reportlist.module#ReportlistPageModule' ,
];
@NgModule(
imports: [ CommonModule, FormsModule, IonicModule,
HttpClientModule, RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [MenuPage]
)
export class MenuPageModule
menu.page.ts
import Component, OnInit from '@angular/core';
import Router, RouterEvent from '@angular/router';
@Component(
selector: 'app-menu',
templateUrl: './menu.page.html',
styleUrls: ['./menu.page.scss'],
)
export class MenuPage implements OnInit
selectedPath = '';
public pages = [
title: 'Profile',
url: '/menu/profile'
,
title: 'Report',
url: '/menu/reportlist'
];
constructor(private router: Router)
this.router.events.subscribe((event: RouterEvent) =>
this.selectedPath = event.url;
);
ngOnInit()
The result is still at login page and unable to go to another page. But authentication stage is passed when I print out. Please help me.
add a comment |
I have created login with menu pages in ionic. I am not able to go to menu page after authentication stage. It didn't show the error too.
Could you please help me?
Here is my code I have tried.
app.routing.module.ts
import NgModule from '@angular/core';
import PreloadAllModules, RouterModule, Routes from '@angular/router';
import AuthGuard from './guards/auth.guard';
const routes: Routes = [
path: '', redirectTo: 'login', pathMatch: 'full' ,
path: 'login', loadChildren: './public/login/login.module#LoginPageModule' ,
path: 'menu', canActivate: [AuthGuard],
loadChildren: './protected/menu/menu.module#MenuPageModule'
,
path: 'reportlist', canActivate: [AuthGuard],loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
];
@NgModule(
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
)
export class AppRoutingModule
app.component.ts
import Component from '@angular/core';
import Router from '@angular/router';
import Platform from '@ionic/angular';
import SplashScreen from '@ionic-native/splash-screen/ngx';
import StatusBar from '@ionic-native/status-bar/ngx';
import OraclemcsService from './services/oraclemcs.service';
@Component(
selector: 'app-root',
templateUrl: 'app.component.html'
)
export class AppComponent
public appPages = [
title: 'Login',
url: '/login',
icon: 'login',
render: true
,
/*
title: 'ReportList',
url: '/reportlist',
icon: 'list',
render: false
, */
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
public stateFlag = false;
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private authService: OraclemcsService,
private router: Router
)
this.initializeApp();
initializeApp()
this.platform.ready().then(() =>
this.statusBar.styleDefault();
this.splashScreen.hide();
this.authService.authenticationState.subscribe(state=>
if (state)
this.stateFlag = true;
this.router.navigate(['menu']);
// this.router.navigate(['menu']);
this.appPages = [
title: 'profile',
url: '/profile',
icon: 'person',
render: false
,
title: 'reportList',
url: '/reportlist',
icon: 'list',
render: false
,
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
else
this.router.navigate(['login']);
this.stateFlag = false;
this.appPages = [
title: 'Login',
url: '/login',
icon: 'log-in',
render: true
];
);
);
logout()
this.authService.logout();
login.page.html
<ion-header>
<ion-toolbar>
<ion-buttons slot="end">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title color="primary">Care Mobile</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-row justify-content-center>
<ion-col align-self-center size-md="6" size-lg="5" size-xs="12">
<div text-center>
<ion-text color="primary">
<h3>Login</h3>
</ion-text>
</div>
<div padding>
<ion-item>
<ion-input type="text" [(ngModel)]="username" placeholder="Username"></ion-input>
</ion-item>
<ion-item>
<ion-input type="password" [(ngModel)]="password" placeholder="Password"></ion-input>
</ion-item>
</div>
<div padding>
<ion-button color="primary" (click)="login()" expand="block">Login</ion-button>
<!--ion-button (click)="callweblogicservice()" expand="block">CallService</ion-button-->
<!--ion-button (click)="logoutweblogic()" expand="block">weblogic logout</ion-button-->
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
login.module.ts
import NgModule from '@angular/core';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import LoginPage from './login.page';
const routes: Routes = [
path: '',
component: LoginPage
];
@NgModule(
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [LoginPage]
)
export class LoginPageModule
login.page.ts
import Component, OnInit from '@angular/core';
import OraclemcsService from './../../services/oraclemcs.service';
import MenuController from '@ionic/angular';
@Component(
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
)
export class LoginPage implements OnInit
public username: string;
public password: string;
constructor(private authService: OraclemcsService, private NavCtrl: MenuController )
ngOnInit()
login()
console.log('User Name & Password' + this.username + this.password);
this.authService.login(this.username, this.password);
this.password = null;
//code to login to WEBLOGIC
//this.authService.loginWeblogic(this.username , this.password);
menu.page.html
<ion-split-pane>
<ion-menu contentId="content">
<ion-header>
<ion-toolbar>
<ion-title>CARE</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-menu-toggle auto-hide="false" *ngFor="let p of pages">
<ion-item [routerLink]="p.url" routerDirection="root" [class.active-item]="selectedPath === p.url">
<ion-label>
p.title
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet id="content" main></ion-router-outlet>
</ion-split-pane>
menu.module.ts
import NgModule from '@angular/core';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import MenuPage from './menu.page';
import AuthGuard from 'src/app/guards/auth.guard';
//import BrowserModule from '@angular/platform-browser';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import HttpClientModule from '@angular/common/http';
//import AppRoutingModule from 'src/app/app-routing.module';
const routes: Routes = [
path: 'menu',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
,
path: '',
redirectTo: './reportlist/reportlist.module#ReportlistPageModule' ,
];
@NgModule(
imports: [ CommonModule, FormsModule, IonicModule,
HttpClientModule, RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [MenuPage]
)
export class MenuPageModule
menu.page.ts
import Component, OnInit from '@angular/core';
import Router, RouterEvent from '@angular/router';
@Component(
selector: 'app-menu',
templateUrl: './menu.page.html',
styleUrls: ['./menu.page.scss'],
)
export class MenuPage implements OnInit
selectedPath = '';
public pages = [
title: 'Profile',
url: '/menu/profile'
,
title: 'Report',
url: '/menu/reportlist'
];
constructor(private router: Router)
this.router.events.subscribe((event: RouterEvent) =>
this.selectedPath = event.url;
);
ngOnInit()
The result is still at login page and unable to go to another page. But authentication stage is passed when I print out. Please help me.
You have an 'AuthGuard' in your route. Could be a problem with your AuthGuard code. Could you paste your AuthGuard code?
– ajai Jothi
Mar 25 at 6:41
@ajaiJothi Now, The menu has been appeared when I removed menu from path and left it black. Thank you so much for your time.
– Maxim
Mar 25 at 7:49
add a comment |
I have created login with menu pages in ionic. I am not able to go to menu page after authentication stage. It didn't show the error too.
Could you please help me?
Here is my code I have tried.
app.routing.module.ts
import NgModule from '@angular/core';
import PreloadAllModules, RouterModule, Routes from '@angular/router';
import AuthGuard from './guards/auth.guard';
const routes: Routes = [
path: '', redirectTo: 'login', pathMatch: 'full' ,
path: 'login', loadChildren: './public/login/login.module#LoginPageModule' ,
path: 'menu', canActivate: [AuthGuard],
loadChildren: './protected/menu/menu.module#MenuPageModule'
,
path: 'reportlist', canActivate: [AuthGuard],loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
];
@NgModule(
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
)
export class AppRoutingModule
app.component.ts
import Component from '@angular/core';
import Router from '@angular/router';
import Platform from '@ionic/angular';
import SplashScreen from '@ionic-native/splash-screen/ngx';
import StatusBar from '@ionic-native/status-bar/ngx';
import OraclemcsService from './services/oraclemcs.service';
@Component(
selector: 'app-root',
templateUrl: 'app.component.html'
)
export class AppComponent
public appPages = [
title: 'Login',
url: '/login',
icon: 'login',
render: true
,
/*
title: 'ReportList',
url: '/reportlist',
icon: 'list',
render: false
, */
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
public stateFlag = false;
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private authService: OraclemcsService,
private router: Router
)
this.initializeApp();
initializeApp()
this.platform.ready().then(() =>
this.statusBar.styleDefault();
this.splashScreen.hide();
this.authService.authenticationState.subscribe(state=>
if (state)
this.stateFlag = true;
this.router.navigate(['menu']);
// this.router.navigate(['menu']);
this.appPages = [
title: 'profile',
url: '/profile',
icon: 'person',
render: false
,
title: 'reportList',
url: '/reportlist',
icon: 'list',
render: false
,
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
else
this.router.navigate(['login']);
this.stateFlag = false;
this.appPages = [
title: 'Login',
url: '/login',
icon: 'log-in',
render: true
];
);
);
logout()
this.authService.logout();
login.page.html
<ion-header>
<ion-toolbar>
<ion-buttons slot="end">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title color="primary">Care Mobile</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-row justify-content-center>
<ion-col align-self-center size-md="6" size-lg="5" size-xs="12">
<div text-center>
<ion-text color="primary">
<h3>Login</h3>
</ion-text>
</div>
<div padding>
<ion-item>
<ion-input type="text" [(ngModel)]="username" placeholder="Username"></ion-input>
</ion-item>
<ion-item>
<ion-input type="password" [(ngModel)]="password" placeholder="Password"></ion-input>
</ion-item>
</div>
<div padding>
<ion-button color="primary" (click)="login()" expand="block">Login</ion-button>
<!--ion-button (click)="callweblogicservice()" expand="block">CallService</ion-button-->
<!--ion-button (click)="logoutweblogic()" expand="block">weblogic logout</ion-button-->
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
login.module.ts
import NgModule from '@angular/core';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import LoginPage from './login.page';
const routes: Routes = [
path: '',
component: LoginPage
];
@NgModule(
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [LoginPage]
)
export class LoginPageModule
login.page.ts
import Component, OnInit from '@angular/core';
import OraclemcsService from './../../services/oraclemcs.service';
import MenuController from '@ionic/angular';
@Component(
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
)
export class LoginPage implements OnInit
public username: string;
public password: string;
constructor(private authService: OraclemcsService, private NavCtrl: MenuController )
ngOnInit()
login()
console.log('User Name & Password' + this.username + this.password);
this.authService.login(this.username, this.password);
this.password = null;
//code to login to WEBLOGIC
//this.authService.loginWeblogic(this.username , this.password);
menu.page.html
<ion-split-pane>
<ion-menu contentId="content">
<ion-header>
<ion-toolbar>
<ion-title>CARE</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-menu-toggle auto-hide="false" *ngFor="let p of pages">
<ion-item [routerLink]="p.url" routerDirection="root" [class.active-item]="selectedPath === p.url">
<ion-label>
p.title
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet id="content" main></ion-router-outlet>
</ion-split-pane>
menu.module.ts
import NgModule from '@angular/core';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import MenuPage from './menu.page';
import AuthGuard from 'src/app/guards/auth.guard';
//import BrowserModule from '@angular/platform-browser';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import HttpClientModule from '@angular/common/http';
//import AppRoutingModule from 'src/app/app-routing.module';
const routes: Routes = [
path: 'menu',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
,
path: '',
redirectTo: './reportlist/reportlist.module#ReportlistPageModule' ,
];
@NgModule(
imports: [ CommonModule, FormsModule, IonicModule,
HttpClientModule, RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [MenuPage]
)
export class MenuPageModule
menu.page.ts
import Component, OnInit from '@angular/core';
import Router, RouterEvent from '@angular/router';
@Component(
selector: 'app-menu',
templateUrl: './menu.page.html',
styleUrls: ['./menu.page.scss'],
)
export class MenuPage implements OnInit
selectedPath = '';
public pages = [
title: 'Profile',
url: '/menu/profile'
,
title: 'Report',
url: '/menu/reportlist'
];
constructor(private router: Router)
this.router.events.subscribe((event: RouterEvent) =>
this.selectedPath = event.url;
);
ngOnInit()
The result is still at login page and unable to go to another page. But authentication stage is passed when I print out. Please help me.
I have created login with menu pages in ionic. I am not able to go to menu page after authentication stage. It didn't show the error too.
Could you please help me?
Here is my code I have tried.
app.routing.module.ts
import NgModule from '@angular/core';
import PreloadAllModules, RouterModule, Routes from '@angular/router';
import AuthGuard from './guards/auth.guard';
const routes: Routes = [
path: '', redirectTo: 'login', pathMatch: 'full' ,
path: 'login', loadChildren: './public/login/login.module#LoginPageModule' ,
path: 'menu', canActivate: [AuthGuard],
loadChildren: './protected/menu/menu.module#MenuPageModule'
,
path: 'reportlist', canActivate: [AuthGuard],loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
];
@NgModule(
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
)
export class AppRoutingModule
app.component.ts
import Component from '@angular/core';
import Router from '@angular/router';
import Platform from '@ionic/angular';
import SplashScreen from '@ionic-native/splash-screen/ngx';
import StatusBar from '@ionic-native/status-bar/ngx';
import OraclemcsService from './services/oraclemcs.service';
@Component(
selector: 'app-root',
templateUrl: 'app.component.html'
)
export class AppComponent
public appPages = [
title: 'Login',
url: '/login',
icon: 'login',
render: true
,
/*
title: 'ReportList',
url: '/reportlist',
icon: 'list',
render: false
, */
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
public stateFlag = false;
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private authService: OraclemcsService,
private router: Router
)
this.initializeApp();
initializeApp()
this.platform.ready().then(() =>
this.statusBar.styleDefault();
this.splashScreen.hide();
this.authService.authenticationState.subscribe(state=>
if (state)
this.stateFlag = true;
this.router.navigate(['menu']);
// this.router.navigate(['menu']);
this.appPages = [
title: 'profile',
url: '/profile',
icon: 'person',
render: false
,
title: 'reportList',
url: '/reportlist',
icon: 'list',
render: false
,
title: 'menu',
url: '/menu',
icon: 'list',
render: false
];
else
this.router.navigate(['login']);
this.stateFlag = false;
this.appPages = [
title: 'Login',
url: '/login',
icon: 'log-in',
render: true
];
);
);
logout()
this.authService.logout();
login.page.html
<ion-header>
<ion-toolbar>
<ion-buttons slot="end">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title color="primary">Care Mobile</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-row justify-content-center>
<ion-col align-self-center size-md="6" size-lg="5" size-xs="12">
<div text-center>
<ion-text color="primary">
<h3>Login</h3>
</ion-text>
</div>
<div padding>
<ion-item>
<ion-input type="text" [(ngModel)]="username" placeholder="Username"></ion-input>
</ion-item>
<ion-item>
<ion-input type="password" [(ngModel)]="password" placeholder="Password"></ion-input>
</ion-item>
</div>
<div padding>
<ion-button color="primary" (click)="login()" expand="block">Login</ion-button>
<!--ion-button (click)="callweblogicservice()" expand="block">CallService</ion-button-->
<!--ion-button (click)="logoutweblogic()" expand="block">weblogic logout</ion-button-->
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
login.module.ts
import NgModule from '@angular/core';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import LoginPage from './login.page';
const routes: Routes = [
path: '',
component: LoginPage
];
@NgModule(
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [LoginPage]
)
export class LoginPageModule
login.page.ts
import Component, OnInit from '@angular/core';
import OraclemcsService from './../../services/oraclemcs.service';
import MenuController from '@ionic/angular';
@Component(
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
)
export class LoginPage implements OnInit
public username: string;
public password: string;
constructor(private authService: OraclemcsService, private NavCtrl: MenuController )
ngOnInit()
login()
console.log('User Name & Password' + this.username + this.password);
this.authService.login(this.username, this.password);
this.password = null;
//code to login to WEBLOGIC
//this.authService.loginWeblogic(this.username , this.password);
menu.page.html
<ion-split-pane>
<ion-menu contentId="content">
<ion-header>
<ion-toolbar>
<ion-title>CARE</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-menu-toggle auto-hide="false" *ngFor="let p of pages">
<ion-item [routerLink]="p.url" routerDirection="root" [class.active-item]="selectedPath === p.url">
<ion-label>
p.title
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet id="content" main></ion-router-outlet>
</ion-split-pane>
menu.module.ts
import NgModule from '@angular/core';
import Routes, RouterModule from '@angular/router';
import IonicModule from '@ionic/angular';
import MenuPage from './menu.page';
import AuthGuard from 'src/app/guards/auth.guard';
//import BrowserModule from '@angular/platform-browser';
import CommonModule from '@angular/common';
import FormsModule from '@angular/forms';
import HttpClientModule from '@angular/common/http';
//import AppRoutingModule from 'src/app/app-routing.module';
const routes: Routes = [
path: 'menu',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
,
path: '',
redirectTo: './reportlist/reportlist.module#ReportlistPageModule' ,
];
@NgModule(
imports: [ CommonModule, FormsModule, IonicModule,
HttpClientModule, RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [MenuPage]
)
export class MenuPageModule
menu.page.ts
import Component, OnInit from '@angular/core';
import Router, RouterEvent from '@angular/router';
@Component(
selector: 'app-menu',
templateUrl: './menu.page.html',
styleUrls: ['./menu.page.scss'],
)
export class MenuPage implements OnInit
selectedPath = '';
public pages = [
title: 'Profile',
url: '/menu/profile'
,
title: 'Report',
url: '/menu/reportlist'
];
constructor(private router: Router)
this.router.events.subscribe((event: RouterEvent) =>
this.selectedPath = event.url;
);
ngOnInit()
The result is still at login page and unable to go to another page. But authentication stage is passed when I print out. Please help me.
edited Mar 25 at 6:36
Johar Zaman
536514
536514
asked Mar 25 at 2:32
MaximMaxim
479
479
You have an 'AuthGuard' in your route. Could be a problem with your AuthGuard code. Could you paste your AuthGuard code?
– ajai Jothi
Mar 25 at 6:41
@ajaiJothi Now, The menu has been appeared when I removed menu from path and left it black. Thank you so much for your time.
– Maxim
Mar 25 at 7:49
add a comment |
You have an 'AuthGuard' in your route. Could be a problem with your AuthGuard code. Could you paste your AuthGuard code?
– ajai Jothi
Mar 25 at 6:41
@ajaiJothi Now, The menu has been appeared when I removed menu from path and left it black. Thank you so much for your time.
– Maxim
Mar 25 at 7:49
You have an 'AuthGuard' in your route. Could be a problem with your AuthGuard code. Could you paste your AuthGuard code?
– ajai Jothi
Mar 25 at 6:41
You have an 'AuthGuard' in your route. Could be a problem with your AuthGuard code. Could you paste your AuthGuard code?
– ajai Jothi
Mar 25 at 6:41
@ajaiJothi Now, The menu has been appeared when I removed menu from path and left it black. Thank you so much for your time.
– Maxim
Mar 25 at 7:49
@ajaiJothi Now, The menu has been appeared when I removed menu from path and left it black. Thank you so much for your time.
– Maxim
Mar 25 at 7:49
add a comment |
1 Answer
1
active
oldest
votes
I just remove the menu and leave it blank as below. The menu appeared.
path: '',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330561%2funable-to-route-to-menu-page-from-login-page-in-ionic%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I just remove the menu and leave it blank as below. The menu appeared.
path: '',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
add a comment |
I just remove the menu and leave it blank as below. The menu appeared.
path: '',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
add a comment |
I just remove the menu and leave it blank as below. The menu appeared.
path: '',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
I just remove the menu and leave it blank as below. The menu appeared.
path: '',
component: MenuPage,
children:[
path: 'reportlist', canActivate: [AuthGuard], loadChildren: './reportlist/reportlist.module#ReportlistPageModule' ,
path: 'profile', canActivate: [AuthGuard], loadChildren: './protected/profile/profile.module#ProfilePageModule' ,
path: 'profile-edit', canActivate: [AuthGuard], loadChildren: './protected/profile-edit/profile-edit.module#ProfileEditPageModule' ,
path: 'report-detail', canActivate: [AuthGuard], loadChildren: './protected/report-detail/report-detail.module#ReportDetailPageModule' ,
path: 'report-create', canActivate: [AuthGuard], loadChildren: './protected/report-create/report-create.module#ReportCreatePageModule' ,
]
answered Mar 25 at 7:51
MaximMaxim
479
479
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330561%2funable-to-route-to-menu-page-from-login-page-in-ionic%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have an 'AuthGuard' in your route. Could be a problem with your AuthGuard code. Could you paste your AuthGuard code?
– ajai Jothi
Mar 25 at 6:41
@ajaiJothi Now, The menu has been appeared when I removed menu from path and left it black. Thank you so much for your time.
– Maxim
Mar 25 at 7:49