Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Clear the view cache in Ionic React

I am facing exactly the same problem as this other question where my Ionic react application caches some views so that when a user logs out and logs in directly with another account, they see for a few seconds the previous data (list of news for example) of the previous user. So the solution is to clear all the cached views when the user access the login view.

This solution proposes to add this code in the view:

$scope.$on("$ionicView.enter", function () {
  $ionicHistory.clearCache();
  $ionicHistory.clearHistory();
});

However this is not the same API used in Ionic v5 for react. I could replaced the event listener with:

import { useIonViewWillEnter } from '@ionic/react'

useIonViewWillEnter(() => {
  // ...
})

But what is the equivalent of:

$ionicHistory.clearCache();
$ionicHistory.clearHistory();

I didn't find anything in the official doc so if someone has an idea I will really appreciate some help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In the state definition in app.js you can add cache:false to disable caching (See Disable cache within state provider in the Ionic docs. Or, you can keep caching except when you know data has changed.

If you're already on the page, you can do, $state.go($state.currentState, {}, {reload:true})

If you're on another state and want to go back to the state that is normally cached but you want it to be refreshed, you can do, $ionicHistory.clearCache().then(function(){ $state.go('app.fooState') })

Note, the latter requires clearCache to return a promise. See the changes I made in this pull request and compare the implementation of clearCache that you have now with mine: https://github.com/driftyco/ionic/pull/3724

Hope This Works!!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!