how to redirect in ionic react


import React, {Component, useCallback, useContext} from 'react';
import {NavContext} from '@ionic/react';

// Functional component example
function MyComponent() {
const {navigate} = useContext(NavContext);

// Call this function when required to redirect with the back animation
const redirect = useCallback(
() => navigate('/new/address', 'back'),
[navigate]
);
}

// Class component example
class MyComponent extends Component {
static contextType = NavContext;

// Call this method when required to redirect with the back animation
redirect() {
this.context.navigate('/new/address', 'back');
}
}

www.codegrepper.com
www.stackoverflow.com

how to redirect react router from the app components


state = { redirect: null };

render() {
if (this.state.redirect) {
return <Redirect to={this.state.redirect} />
}
return(
// Your Code goes here
)
}

// update the redirect
this.setState({ redirect: "/someRoute" });

state = { redirect: null };
render() {
if (this.state.redirect) {
return <Redirect to={this.state.redirect} />
}
return(
// Your Code goes here
)
}

www.codegrepper.com
www.stackoverflow.com

how to redirect to another page in javascript on submit type


<script type="text/javascript" language="javascript">
function redirect()
{
window.location.href="login.php";
}
</script>
<form name="form1" id="form1" method="post">
<input type="submit" class="button4" name="order"
id="order" value="Place Order" onclick="redirect();" >
</form>

www.codegrepper.com
www.stackoverflow.com