After going through Clear History and Reload Page on Login/Logout Using Ionic Framework
I want to know same question, but for ionic2 using typescript.
On login and logout I need reload the app.ts
, because there are classes that run libraries on construct.
it would be basically redirect to home and reload.
Ionic provides the same by using <ion-refresher> component to add a pull-down feature. The <ion-refresher> component provides pull-to-refresh functionality on a content component. An Ionic allows a user to use this pattern on a list of data using touch to retrieve more data.
If you wish to reload the pages on navigating to the same URL then you can use this configuration under your root module: @NgModule({ imports: [ ... RouterModule. forRoot(routes, { onSameUrlNavigation: 'reload'}) .... ], declarations: [ ... ], bootstrap: [ ... ] })
Refresher provides pull-to-refresh functionality on a content component. The pull-to-refresh pattern lets a user pull down on a list of data in order to retrieve more data. Data should be modified during the refresher's output events.
By default, ionic serve boots up a development server on localhost . To serve to your LAN, specify the --external option, which will use all network interfaces and print the external address(es) on which your app is being served. Try the --lab option to see multiple platforms at once. ionic serve uses the Angular CLI.
Found this answer here, (please note especially the line this.navCtrl.setRoot(this.navCtrl.getActive().component);
which is by far the simplest solution that I've come across to reload present page for Ionic 2 & 3 and later versions of Angular (mine is 4), so credit due accordingly:
RELOAD CURRENT PAGE
import { Component } from '@angular/core';
import { NavController, ModalController} from 'ionic-angular';
@Component({
selector: 'page-example',
templateUrl: 'example.html'
})
export class ExamplePage {
public someVar: any;
constructor(public navCtrl: NavController, private modalCtrl: ModalController) {
}
refreshPage() {
this.navCtrl.setRoot(this.navCtrl.getActive().component);
}
}
If you want to RELOAD A DIFFERENT PAGE please use the following (note this.navCtrl.setRoot(HomePage);
:
import { Component } from '@angular/core';
import { NavController, ModalController} from 'ionic-angular';
import { HomePage } from'../home/home';
@Component({
selector: 'page-example',
templateUrl: 'example.html'
})
export class ExamplePage {
public someVar: any;
constructor(public navCtrl: NavController, private modalCtrl: ModalController) {
}
directToNewPage() {
this.navCtrl.setRoot(HomePage);
}
}
Ionic 1
I haven't used Ionic 2 but currently i m using Ionic 1.2 and if they are still using ui-router than you can use reload: true in ui-sref
or you can add below code to your logout controller
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
Angular 2
Use
$window.location.reload();
or
location.reload();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With