4

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

The following code correctly performs a redirect, but doesn't actually render the component related to the redirection url.
Below is my code, a small adaptation to the code given 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 refreshing the browser after the redirection, the page is correctly displayed.

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

History:

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

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

const history = syncHistoryWithStore(createBrowserHistory(), store);
Community
  • 1
  • 1
html_programmer
  • 14,612
  • 12
  • 59
  • 125

0 Answers0