Answer the question
In order to leave comments, you need to log in
What changes in React logic when using a HOC component in routing?
Hello. I'm trying to understand the logic. There is a simplified code:
import React from 'react';
import './App.css';
import { Switch, Route, Redirect, BrowserRouter } from "react-router-dom";
function ProtectedRoute({ component: Component, ...props }) {
return (
<Route exact path={props.path}>
<Redirect to="/sign-in" />
</Route>)
}
function App() {
return (
<BrowserRouter>
<div className="App">
<Switch>
**Вариант 1:** <ProtectedRoute path="/" />
**Вариант 2:** <Route exact path="/">
<Redirect to="sign-in" />
</Route>
<Route path="/sign-in">
<div>Login</div>
</Route>
<Route path="/sign-up">
<div>Register</div>
</Route>
</Switch>
</div>
</BrowserRouter>
);
}
export default App;
return (
<Route exact path={props.path}>
<Redirect to="/sign-in" />
</Route>)
return (
<Route exact path={props.path}>
{() => <Redirect to="/sign-in" />}
</Route>)
<Redirect to="/sign-in" /> и () => <Redirect to="/sign-in" />
in this case?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question