Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48979

Conditionally redirecting to another page

$
0
0

Using Ionic React, I am trying to Redirect a user to a different page based on some state - for this example, it is local storage but it could also be remote state however retrieving this state is async.

Traditionally, I’d return a Redirect component but this brakes all kinds of functionality in Ionic and it’s been widely reported in Github Issues without any proper solutions. I’ve also tried to use history.replace which works but has a small downside.

I guess I am wondering how others have resolved this problem. The particular use case is: user clicks on a tab - we need to check if they completed onboarding for this feature - if they have completed, we show them the main page, otherwise redirect them to an “intro” page.

Contrived example:

function Academy() {
  const { surveyComplete, loading } = useAcademyWelcome()

  if (loading || surveyComplete === undefined) return null

  if(surveyComplete !== true) return <Redirect to='/academy/survey' />

  return (
    <IonPage>
      <IonContent>
        <InvestingPosts />
      </IonContent>
    <IonPage>
  )
}

The above create several problems, the main one being If the user moves to a different tab, they cannot return to this tab and continue where they left off as the page never renders.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48979

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>