Having same version for react and react-dom "react": "^18.2.0", "react-dom": "^18.2.0" and history is latest "history": "^5.3.0",
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import SignInSide from "./components/mui/signIn/SignInSide";
import store from "./Store/Store";
import { Provider } from "react-redux";
import Dashboard from "./components/mui/Dashboard";
import history from './utils/history';
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<Provider store={store}>
<Router history={history}>
<Routes>
<Route path="/login" element={<SignInSide />} />
<Route path="/home" element={<Dashboard />} >
</Route>
<Route path="/" element={<App />} />
</Routes>
</Router>
</Provider>
</React.StrictMode>
);
function SignInSide(props) {
const handleSubmit = (event) => {
event.preventDefault();
const form = new FormData(event.currentTarget);
let user = {
email: form.get('email'),
password: form.get('password')
}
console.log(user);
props.signIn(user);
};
return (....);
Calling handleSubmit from singIn button
import { createBrowserHistory } from "history";
export function LoginUser(LogInData) {
let navigate = useNavigate;
return (dispatch) => {
dispatch(AuthActions.userSignIn());
signInWithEmailAndPassword(auth, LogInData.email, LogInData.password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
dispatch(AuthActions.userSignInSuccess(user));
setPersistence(auth, browserSessionPersistence)
.then(() => {
return signInWithEmailAndPassword(
auth,
LogInData.email,
LogInData.password
);
})
.catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
});
history.push("/home");
// console.log(store);
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
dispatch(AuthActions.userSignInFailed(error));
});
};
}
Using history.push("/home") this only Url replaced not component loading so please provide the solution with using latest npm version(if any) or suggest ready template ASAP.