InterviewHubPRO
Section Overview
Q88

Question 88 of 445

Part 2: React Router & Navigation (78 - 88)

20%
React & Modern Frontend (445 Qs)•Part 2: React Router & Navigation (78 - 88)

How to perform automatic redirect after login?

The react-router package provides <Redirect> component in React Router. Rendering a <Redirect> will navigate to a new location. Like server-side redirects, the new location will override the current location in the history stack.

javascript
import { Redirect } from "react-router";

export default function Login {
 if (this.state.isLoggedIn === true) {
   return <Redirect to="/your/redirect/page" />;
 } else {
   return <div>{"Login Please"}</div>;
 }
}
<details><summary><b>See Class</b></summary> <p>
jsx
import React, { Component } from "react";
import { Redirect } from "react-router";

export default class LoginComponent extends Component {
render() {
 if (this.state.isLoggedIn === true) {
   return <Redirect to="/your/redirect/page" />;
 } else {
   return <div>{"Login Please"}</div>;
 }
}
}
</p> </details>

React Internationalization