// React Router v6
// pass data between routes
// ---------------------------------------------------------------------
// sender.js/jsx
import { useNavigate } from "react-router-dom";
const navigate = useNavigate();
navigate('/other-page', { state: { username: 'user', password: '696' } });
// ---------------------------------------------------------------------
// receiver.js/jsx
import { useLocation } from "react-router-dom";
const location = useLocation();
console.log(location.state) // gives: {username: 'user', password: '696'}
import {useLocation} from 'react-router-dom';
const Register=()=>{
const location = useLocation()
//store the state in a variable if you want
//location.state then the property or object you want
const Name = location.state.name
return(
<div>
hello my name is {Name}
</div>
)
}
<Link to='register' state={{name:'zayne'}}>