I am implementing a simple login page, and I want to forward the user to another page/path after selecting an identity.
import {useState} from "react";
import { Navigate } from 'react-router-dom';
import Container from 'react-bootstrap/Container';
import Select from 'react-select';
import './Login.css';
export default function Login(){
const [technician,setTechnician]=useState();
let options=[
{label:"Jack", value:"2432244cvdsffsd2342434"}
];
let doLogin=()=>{
if (technician){
sessionStorage.setItem("technican",JSON.stringify(technician));
return <Navigate to='/request'/>
}else {
alert("Please select your name to login.");
}
}
let handleChange=(value)=>{
setTechnician(value);
}
return (
<Container>
Login:
<Select
isClearable
onChange={handleChange}
options={options}
placeholder="Please select your name to login"/>
<button onClick={doLogin}>Login</button>
</Container>
)
}
I am using react-router v6.
"react-router-dom": "^6.0.2"
Expected Result:
- user selects identity from the drop-down.
- Click on the "login" button. It should forward the user to the "/request" path
Actual Result:
The page does not forward users to the "/request" path.
Would you tell me what the problem is?