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 redirect

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

PREVIOUS NEXT
Code Example
Javascript :: npm run test:coverage command in jest 
Javascript :: javascript change long digit ot k,m 
Javascript :: scroll to top jquery 
Javascript :: useHistory is not exported form react-router-dom 
Javascript :: jquery close popup when click outside 
Javascript :: parse integer javascript 
Javascript :: decet wheter react app in development or production 
Javascript :: validator pattern angular for number only 
Javascript :: unique values from array of objects 
Javascript :: javascript check if all capital letter 
Javascript :: vh not working on phone 
Javascript :: copy an array without pointer in angular 
Javascript :: hide status bar react native 
Javascript :: reset date input javascript 
Javascript :: window.history.pushstate typescript 
Javascript :: jquery click event 
Javascript :: props.history.push with data 
Javascript :: convert firestore timnestamp to javascript 
Javascript :: yarn react-native-async-storage 
Javascript :: javascript select all table rows 
Javascript :: ajax post 
Javascript :: once page loaded run function 
Javascript :: wait for the dom to load javascript 
Javascript :: npm err! 503 service unavailable proxy 
Javascript :: &nbsp replace javascript 
Javascript :: check if class is active jquery 
Javascript :: go to previous page 
Javascript :: javascript replace element 
Javascript :: angular create component without test 
Javascript :: react get input value on button click functional component 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =