Answer the question
In order to leave comments, you need to log in
How to make a redirect in a component that knows nothing about route?
There is a main component:
ReactDOM.render(
<BrowserRouter>
<Switch>
<Route exact path='/' render={() => (isAuth() ? (<Redirect to="/orders"/>) : (<Redirect to="/login"/>))}/>
<Route exact path='/products' render={() => (isAuth() ? (<Redirect to="/orders"/>) : (<Redirect to="/login"/>))}/>
<Route exact path='/orders' render={() => (isAuth() ? (<PageOrders/>) : (<Redirect to="/login"/>))}/>
<Route exact path='/add_order' render={() => (isAuth() ? (<PageAddOrder/>) : (<Redirect to="/login"/>))}/>
<Route exact path='/login' render={() => (isAuth() ? (<Redirect to="/orders"/>) : (<Autorize/>))}/>
</Switch>
</BrowserRouter>,
document.getElementById('root'));
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