I am trying to send the user to the login page after an initial animation has finished. It takes two seconds for the animation to execute so I set a settimeout that takes 3 seconds to execute but then it says that it is not possible to load the web page in http://localhost/pages/Login.tsx and it gives me a net::ERR_INVALID_RESPONSE error.
Here is my code:
import React, { useEffect } from 'react';
import { IonApp } from '@ionic/react';
import "./css/main.css";
/* Core CSS required for Ionic components to work properly */
import '@ionic/react/css/core.css';
/* Basic CSS for apps built with Ionic */
import '@ionic/react/css/normalize.css';
import '@ionic/react/css/structure.css';
import '@ionic/react/css/typography.css';
/* Optional CSS utils that can be commented out */
import '@ionic/react/css/padding.css';
import '@ionic/react/css/float-elements.css';
import '@ionic/react/css/text-alignment.css';
import '@ionic/react/css/text-transformation.css';
import '@ionic/react/css/flex-utils.css';
import '@ionic/react/css/display.css';
/* Theme variables */
import './theme/variables.css';
const App: React.FC = () => {
useEffect(() => {
setTimeout(() => {
console.log("set timeout")
var goToLogin: HTMLElement = document.querySelector("#goToLogin") as HTMLElement;
goToLogin?.click();
// window.location = "/pages/Login.tsx";
}, 3000);
}, []);
return(
<IonApp class="app">
<a id="goToLogin" href="./pages/Login.tsx"></a>
<div>
<svg id="core-logo" width="117" height="60" viewBox="0 0 307 157" fill="#fff" xmlns="http://www.w3.org/2000/svg">
<path d="M67.824 78.088H88.56C88.56 83.08 87.744 87.544 86.112 91.48C84.48 95.416 82.224 98.776 79.344 101.56C76.464 104.344 73.056 106.456 69.12 107.896C65.184 109.638 153.848 212.094 153.932 212.742 154.004C213.414 154.1 214.074 154.148 214.722 1288.974 133.336 289.998 132.248C291.054 131.16 291.582 129.48 291.582 127.208ZM283.758 128.744V132.008H281.694V122.312H285.15C286.654 122.312 287.694 122.584 288.27 123.128C288.878 123.64 289.182 124.44 289.182 125.528C289.182 126.328 289.006 126.984 288.654 127.496C288.302 127.976 287.774 128.312 287.07 128.504L289.422 132.008H286.83L284.862 128.744H283.758ZM287.07 125.528C287.07 125.08 286.926 124.744 286.638 124.52C286.35 124.296 285.854 124.184 285.15 124.184H283.758V127.016H285.15C285.854 127.016 286.35 126.904 286.638 126.68C286.926 126.424 287.07 126.04 287.07 125.528Z" fill="white"/>
</svg>
</div>
</IonApp>
);
};
export default App;
How can I redirect to the login page?
Here is my file structure:

UPDATED
Now my app looks like this:
const App: React.FC = () => {
let history = useHistory();
useEffect(() => {
setTimeout(() => {
history.push("/login");
}, 3000);
}, []);
return(
<IonApp class="app">
<IonReactRouter>
<IonRouterOutlet>
<Route exact path="/login" component={Login} />
</IonRouterOutlet>
</IonReactRouter>
<div>
<svg id="core-logo" width="117" height="60" viewBox="0 0 307 157" fill="#fff" xmlns="http://www.w3.org/2000/svg">
<path d="M67.824 78.088H88.56C88.56 83.08 87.744 87.544 86.112 91.48C84.48 95.416 82.224 98.776 12 287.07 128.504L289.422 132.008H286.83L284.862 128.744H283.758ZM287.07 125.528C287.07 125.08 286.926 124.744 286.638 124.52C286.35 124.296 285.854 124.184 285.15 124.184H283.758V127.016H285.15C285.854 127.016 286.35 126.904 286.638 126.68C286.926 126.424 287.07 126.04 287.07 125.528Z" fill="white"/>
</svg>
</div>
</IonApp>
);
};
I also encapsulated the app component in BrowserRouter in index.tsx:
ReactDOM.render(
<React.StrictMode>
<Router>
<App />
</Router>
</React.StrictMode>,
document.getElementById('root')
);
UPDATE 2 Removed the router in index.tsx:
ReactDOM.render(
<React.StrictMode>
{/* <Router> */}
<App />
{/* </Router> */}
</React.StrictMode>,
document.getElementById('root')
);
And used:
useIonViewWillEnter(() => {
setTimeout(() => {
history.push("/login");
}, 3000);
});
Instead of useEffect.
Now I can navigate through the url bar in chrome inspect but every time I render a new page the App page renders again. And I get the following error:
Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.