showing results for - "how to redirect in ionic react"
Matthew
22 Oct 2018
1import React, {Component, useCallback, useContext} from 'react';
2import {NavContext} from '@ionic/react';
3
4// Functional component example
5function MyComponent() {
6  const {navigate} = useContext(NavContext);
7
8  // Call this function when required to redirect with the back animation
9  const redirect = useCallback(
10    () => navigate('/new/address', 'back'),
11    [navigate]
12  );
13}
14
15// Class component example
16class MyComponent extends Component {
17  static contextType = NavContext;
18
19  // Call this method when required to redirect with the back animation
20  redirect() {
21    this.context.navigate('/new/address', 'back');
22  }
23}