Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

redirecting in react

// React Router v6
import { useNavigate, Redirect,Route  } from 'react-router-dom';

#method 1
export function GoHome() {
  let navigate = useNavigate();
  const handleClick = e => {
    e.preventDefault();
    navigate('/home');
  }
  return <button onClick={handleClick}>Go to Home</button>
}

#method 2
<Route exact path="/">
  {loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
</Route>
Comment

react router redirect

<Route exact path="/">
  {loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
</Route>
Comment

redirect react router

<Route exact path="/">
  {loggedIn ? <Redirect to="/profile" /> : <HomePage />}
</Route>
Comment

React redirect

<Redirect to="/somewhere/else" />
Comment

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" });
Comment

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
  )
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: redirect to url in javascript 
Javascript :: redirect browser javascript 
Javascript :: redirect link javascript 
Javascript :: js redirect code 
Javascript :: display none javascript 
Javascript :: vehicle number yup validation 
Javascript :: select first 3 letters js 
Javascript :: array.foreach 
Javascript :: js remove zeros after decimal 
Javascript :: react-native resource android:attr/lStar not found in Android 
Javascript :: javascript line break 
Javascript :: nested destructuring javascript 
Javascript :: how to edit /.prettierrc.json file pretter 
Javascript :: document selector query change value 
Javascript :: document get element by id style 
Javascript :: reload page 
Javascript :: disable unused vars 
Javascript :: check if array does not contain value javascript 
Javascript :: express.json 
Javascript :: checkbox on click jquery 
Javascript :: javascript rupiah format 
Javascript :: javascript show localstorage size 
Javascript :: discordjs delete all messages in channel 
Javascript :: react construct 
Javascript :: display current date and time in react js 
Javascript :: push state array react 
Javascript :: remove time from date javascript 
Javascript :: js check if date is future 
Javascript :: split a message js 
Javascript :: update angular to specific version 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =