Redirection does not display component

This is a continuation of the question:
onEnter is not called in React-Router

The following code performs the redirect correctly, but does not actually display the component associated with the redirect URL.
Below is my code, a slight adaptation to the code mentioned in the previous question.

// Authentication "before" filter
function requireAuth(){
  if(isLoggedIn())
    return <Home />
  else
    return <Redirect to="/front"/>
}

// Render the app
render(
  <Provider store={store}>
      <Router history={history}>
        <App>
          <Switch>
            <Route path="/front" component={Front} />
            <Route path="/home" render={requireAuth} />
            <Route exact path="/" render={requireAuth} />
            <Route path="*" component={NoMatch} />
          </Switch>
        </App>
      </Router>
  </Provider>,
  document.getElementById("lf-app")
)

When updating the browser after redirecting, the page is displayed correctly.

I would expect the rendering to work, but it doesn't ... Is this a bug or a desired behavior?

Story:

... 
import {createBrowserHistory}           from "history";

// Init sagaMiddleware
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
    appReducers,
    applyMiddleware(sagaMiddleware)
);

const history = syncHistoryWithStore(createBrowserHistory(), store);
+4
source share

Source: https://habr.com/ru/post/1672228/


All Articles